久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='qsgPj'><tr id='qsgPj'><dt id='qsgPj'><q id='qsgPj'><span id='qsgPj'><b id='qsgPj'><form id='qsgPj'><ins id='qsgPj'></ins><ul id='qsgPj'></ul><sub id='qsgPj'></sub></form><legend id='qsgPj'></legend><bdo id='qsgPj'><pre id='qsgPj'><center id='qsgPj'></center></pre></bdo></b><th id='qsgPj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qsgPj'><tfoot id='qsgPj'></tfoot><dl id='qsgPj'><fieldset id='qsgPj'></fieldset></dl></div>

    <small id='qsgPj'></small><noframes id='qsgPj'>

      <legend id='qsgPj'><style id='qsgPj'><dir id='qsgPj'><q id='qsgPj'></q></dir></style></legend>
        <bdo id='qsgPj'></bdo><ul id='qsgPj'></ul>

    1. <tfoot id='qsgPj'></tfoot>

      1. Android - 如何使edittext中的所有行都加下劃線(xiàn)?

        Android - How to make all lines in an edittext underlined?(Android - 如何使edittext中的所有行都加下劃線(xiàn)?)

          <small id='c1g6J'></small><noframes id='c1g6J'>

        1. <tfoot id='c1g6J'></tfoot>
            <tbody id='c1g6J'></tbody>

              <bdo id='c1g6J'></bdo><ul id='c1g6J'></ul>

                <legend id='c1g6J'><style id='c1g6J'><dir id='c1g6J'><q id='c1g6J'></q></dir></style></legend>

                  <i id='c1g6J'><tr id='c1g6J'><dt id='c1g6J'><q id='c1g6J'><span id='c1g6J'><b id='c1g6J'><form id='c1g6J'><ins id='c1g6J'></ins><ul id='c1g6J'></ul><sub id='c1g6J'></sub></form><legend id='c1g6J'></legend><bdo id='c1g6J'><pre id='c1g6J'><center id='c1g6J'></center></pre></bdo></b><th id='c1g6J'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='c1g6J'><tfoot id='c1g6J'></tfoot><dl id='c1g6J'><fieldset id='c1g6J'></fieldset></dl></div>
                  本文介紹了Android - 如何使edittext中的所有行都加下劃線(xiàn)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  從教程中我創(chuàng)建了布局:

                  From the tutorial I have created the layout:

                    public static class LinedEditText extends EditText {
                          private Rect mRect;
                          private Paint mPaint;
                  
                          // we need this constructor for LayoutInflater
                          public LinedEditText(Context context, AttributeSet attrs) {
                              super(context, attrs);
                  
                              mRect = new Rect();
                              mPaint = new Paint();
                              mPaint.setStyle(Paint.Style.STROKE);
                              mPaint.setColor(0x80000000);
                          }
                  
                          @Override
                          protected void onDraw(Canvas canvas) {
                              int count = getLineCount();
                              Rect r = mRect;
                              Paint paint = mPaint;
                  
                              for (int i = 0; i < count; i++) {
                                  int baseline = getLineBounds(i, r);
                                  canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
                              }
                  
                              super.onDraw(canvas);
                          }
                      }
                  
                  <view xmlns:android="http://schemas.android.com/apk/res/android"
                      class="com.bbbfr.mynotepad.NotepadText$LinedEditText"
                      android:id="@+id/note"
                      android:background="#ffd6e5"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:padding="5dp"
                      android:scrollbars="vertical"
                      android:fadingEdge="vertical"
                      android:gravity="top"
                      android:textSize="22sp"
                      android:textColor="#000000"
                      android:inputType="textMultiLine"
                      android:capitalize="sentences"
                  />
                  

                  這只會(huì)使第一行加下劃線(xiàn).即使編輯文本中只有一行,是否可以將所有行都加下劃線(xiàn)?

                  This makes only the first line underlined. Is it possible to make all the lines underlined, even if there is only one line in the edtittext?

                  我嘗試改變循環(huán),例如for (int i = 0; i < 5; i++) 但隨后我收到此錯(cuò)誤:

                  I tried changing the loop e.g. for (int i = 0; i < 5; i++) but then I receive this error:

                  04-28 08:29:05.093: E/AndroidRuntime(14398):java.lang.IndexOutOfBoundsException: 2, 1 04-28 08:29:05.093:E/AndroidRuntime(14398):在android.text.PackedIntVector.getValue(PackedIntVector.java:70) 04-2808:29:05.093: E/AndroidRuntime(14398): 在android.text.DynamicLayout.getLineTop(DynamicLayout.java:367) 04-2808:29:05.093: E/AndroidRuntime(14398): 在android.text.Layout.getLineBottom(Layout.java:831) 04-28 08:29:05.093:E/AndroidRuntime(14398):在android.text.Layout.getLineBounds(Layout.java:437) 04-28 08:29:05.093:E/AndroidRuntime(14398):在android.widget.TextView.getLineBounds(TextView.java:4122) 04-2808:29:05.093: E/AndroidRuntime(14398): 在com.bbbfr.mynotepad.NotepadText$LinedEditText.onDraw(NotepadText.java:56)

                  04-28 08:29:05.093: E/AndroidRuntime(14398): java.lang.IndexOutOfBoundsException: 2, 1 04-28 08:29:05.093: E/AndroidRuntime(14398): at android.text.PackedIntVector.getValue(PackedIntVector.java:70) 04-28 08:29:05.093: E/AndroidRuntime(14398): at android.text.DynamicLayout.getLineTop(DynamicLayout.java:367) 04-28 08:29:05.093: E/AndroidRuntime(14398): at android.text.Layout.getLineBottom(Layout.java:831) 04-28 08:29:05.093: E/AndroidRuntime(14398): at android.text.Layout.getLineBounds(Layout.java:437) 04-28 08:29:05.093: E/AndroidRuntime(14398): at android.widget.TextView.getLineBounds(TextView.java:4122) 04-28 08:29:05.093: E/AndroidRuntime(14398): at com.bbbfr.mynotepad.NotepadText$LinedEditText.onDraw(NotepadText.java:56)

                  到這一行:int baseline = getLineBounds(i, r);

                  我還在視圖中設(shè)置了 android:lines="5".

                  I have also set android:lines="5" in the view.

                  推薦答案

                  如果你不介意下劃線(xiàn)與 EditText 中的文本顏色相同,你真的應(yīng)該只是使用內(nèi)置 UnderlineSpan,可以自己創(chuàng)建,也可以通過(guò) Html.fromHtml(...) 間接創(chuàng)建.

                  If you don't mind the underline having the same colour as the text in the EditText, you should really just use the built-in UnderlineSpan, either by creating it yourself or indirectly through Html.fromHtml(...).

                  private void createUnderlinedText() {
                      String text = "I am underlined text
                  Line #2
                  Line #3
                  Line #4
                  Line #5";
                  
                      EditText underlineSpanEditText = (EditText) findViewById(R.id.underlinespan_edittext);
                      SpannableStringBuilder sb = new SpannableStringBuilder(text);
                      sb.setSpan(new UnderlineSpan(), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                      underlineSpanEditText.setText(sb);
                  
                      EditText htmlUnderlineEditText = (EditText) findViewById(R.id.html_underline_edittext);
                      String html = "<u>I am underlined text</br>Line #2</br>Line #3</br>Line #4</br>Line #5</u>";
                      htmlUnderlineEditText.setText(Html.fromHtml(html));
                  }
                  

                  與您當(dāng)前方法的主要區(qū)別在于,這只會(huì)在實(shí)際文本下劃線(xiàn),而不是整個(gè)文本行.例如,如果您運(yùn)行我的代碼片段,您會(huì)發(fā)現(xiàn)下劃線(xiàn)在被 <br/> 斷開(kāi)時(shí)并沒(méi)有延伸到行尾..但是,根據(jù)您之后的行為,這可能不是您想要的.

                  The main difference with your current approach is that this will only underline the actual text, and not the whole text line. For example, if you run my code snippet, you will find that the underline does not extend to the end of the line when it's broken off by the or <br/>. However, depending on the behaviour your after, this may not be what you're looking for.

                  所以如果我理解正確的話(huà),你基本上想在你的EditText中繼續(xù)畫(huà)水平線(xiàn),不管有沒(méi)有文字?您問(wèn)題中的下劃線(xiàn)"部分有點(diǎn)誤導(dǎo),因?yàn)槭聦?shí)證明,這與它幾乎沒(méi)有關(guān)系(在這個(gè)詞的傳統(tǒng)含義中:)).

                  So if I understand you correctly, you basically want to keep drawing horizontal lines in your EditText, no matter wether there is text or not? The 'underline' part in your question was kind of misleading, since, as it turns out, that has little to do with it (in the traditional meaning of the word :)).

                  無(wú)論如何,您不能使用 getLineCount() 因?yàn)樗偸菚?huì)返回包含實(shí)際文本的行數(shù).這意味著您必須用換行符填充"任何剩余空間才能獲得所需的效果,這聽(tīng)起來(lái)有點(diǎn)惡心......更好的選擇可能是將水平線(xiàn)的繪制基于 <的總高度代碼>編輯文本.一個(gè)簡(jiǎn)單的示例,您顯然可以根據(jù)自己的喜好對(duì)其進(jìn)行調(diào)整:

                  Anyways, you can't use getLineCount() since that will always return the number of lines that contain actual text. That would mean you would have to 'fill' any remaing space with new line characters to get the desired effect, which sounds kind of yucky... A better alternative is probably to base the drawing of horizontal lines on the total height of the EditText. A quick example, which you can obviously tweak to your own liking:

                  public class LinedEditText extends EditText {
                      private Paint mPaint = new Paint();
                  
                      public LinedEditText(Context context) {
                          super(context);
                          initPaint();
                      }
                  
                      public LinedEditText(Context context, AttributeSet attrs) {
                          super(context, attrs);
                          initPaint();
                      }
                  
                      public LinedEditText(Context context, AttributeSet attrs, int defStyle) {
                          super(context, attrs, defStyle);
                          initPaint();
                      }
                  
                      private void initPaint() {
                          mPaint.setStyle(Paint.Style.STROKE);
                          mPaint.setColor(0x80000000);
                      }
                  
                      @Override protected void onDraw(Canvas canvas) {
                          int left = getLeft();
                          int right = getRight();
                          int paddingTop = getPaddingTop();
                          int paddingBottom = getPaddingBottom();
                          int paddingLeft = getPaddingLeft();
                          int paddingRight = getPaddingRight();
                          int height = getHeight();
                          int lineHeight = getLineHeight();
                          int count = (height-paddingTop-paddingBottom) / lineHeight;
                  
                          for (int i = 0; i < count; i++) {
                              int baseline = lineHeight * (i+1) + paddingTop;
                              canvas.drawLine(left+paddingLeft, baseline, right-paddingRight, baseline, mPaint);
                          }
                  
                          super.onDraw(canvas);
                      }
                  }
                  

                  結(jié)果如下:

                  這篇關(guān)于Android - 如何使edittext中的所有行都加下劃線(xiàn)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                1. <tfoot id='8RIui'></tfoot><legend id='8RIui'><style id='8RIui'><dir id='8RIui'><q id='8RIui'></q></dir></style></legend>

                  <small id='8RIui'></small><noframes id='8RIui'>

                      • <bdo id='8RIui'></bdo><ul id='8RIui'></ul>

                          <tbody id='8RIui'></tbody>
                        <i id='8RIui'><tr id='8RIui'><dt id='8RIui'><q id='8RIui'><span id='8RIui'><b id='8RIui'><form id='8RIui'><ins id='8RIui'></ins><ul id='8RIui'></ul><sub id='8RIui'></sub></form><legend id='8RIui'></legend><bdo id='8RIui'><pre id='8RIui'><center id='8RIui'></center></pre></bdo></b><th id='8RIui'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8RIui'><tfoot id='8RIui'></tfoot><dl id='8RIui'><fieldset id='8RIui'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 91久久爽久久爽爽久久片 | 国产精品视频播放 | 欧美日韩电影免费观看 | 97视频成人| 97久久精品午夜一区二区 | 成人免费视频观看视频 | 毛片一级电影 | 精品福利一区二区三区 | 欧美精品一区在线发布 | 国产欧美日韩综合精品一区二区 | 亚洲性人人天天夜夜摸 | 成人九区 | 麻豆精品久久久 | 亚洲 欧美 综合 | 日韩欧美中文 | 久久美女网 | 91精品国产综合久久久久久丝袜 | av网站免费观看 | 中文福利视频 | 欧美不卡一区二区三区 | 精品国产18久久久久久二百 | 日韩精品一区二区三区高清免费 | 麻豆国产一区二区三区四区 | 国产激情视频在线免费观看 | 在线观看视频福利 | 日本三级网址 | 一区二区电影 | 在线精品国产 | 九九热这里只有精品在线观看 | 99re在线播放 | 最新国产视频 | 国产乱码精品一区二区三区中文 | 国产欧美精品 | 久久久青草 | 国产精品视频观看 | 午夜精品一区二区三区在线观看 | 国产一区二区三区亚洲 | 日本久久网 | 亚洲一区在线日韩在线深爱 | 亚洲三级国产 | 日本不卡一区二区三区 |