pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="4akgogq" 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中的所有行都加下劃線?

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

          <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="kokmqi0" id='c1g6J'><tfoot id='c1g6J'></tfoot><dl id='c1g6J'><fieldset id='c1g6J'></fieldset></dl></div>
                  本文介紹了Android - 如何使edittext中的所有行都加下劃線?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  從教程中我創建了布局:

                  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"
                  />
                  

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

                  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?

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

                  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);

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

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

                  推薦答案

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

                  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));
                  }
                  

                  與您當前方法的主要區別在于,這只會在實際文本下劃線,而不是整個文本行.例如,如果您運行我的代碼片段,您會發現下劃線在被 <br/> 斷開時并沒有延伸到行尾..但是,根據您之后的行為,這可能不是您想要的.

                  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.

                  所以如果我理解正確的話,你基本上想在你的EditText中繼續畫水平線,不管有沒有文字?您問題中的下劃線"部分有點誤導,因為事實證明,這與它幾乎沒有關系(在這個詞的傳統含義中:)).

                  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 :)).

                  無論如何,您不能使用 getLineCount() 因為它總是會返回包含實際文本的行數.這意味著您必須用換行符填充"任何剩余空間才能獲得所需的效果,這聽起來有點惡心......更好的選擇可能是將水平線的繪制基于 <的總高度代碼>編輯文本.一個簡單的示例,您顯然可以根據自己的喜好對其進行調整:

                  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);
                      }
                  }
                  

                  結果如下:

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

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 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="gkq0iga" id='8RIui'><tfoot id='8RIui'></tfoot><dl id='8RIui'><fieldset id='8RIui'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 无锡装修装潢公司,口碑好的装饰装修公司-无锡索美装饰设计工程有限公司 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 喷砂机厂家_自动除锈抛丸机价格-成都泰盛吉自动化喷砂设备 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 金属管浮子流量计_金属转子流量计厂家-淮安润中仪表科技有限公司 | 聚氨酯催化剂K15,延迟催化剂SA-1,叔胺延迟催化剂,DBU,二甲基哌嗪,催化剂TMR-2,-聚氨酯催化剂生产厂家 | 视频教程导航网_视频教程之家_视频教程大全_最新视频教程分享发布平台 | 防爆电机_防爆电机型号_河南省南洋防爆电机有限公司 | 长信科技产业园官网_西安厂房_陕西标准工业厂房 | 列管冷凝器,刮板蒸发器,外盘管反应釜厂家-无锡曼旺化工设备有限公司 | 泰国专线_泰国物流专线_广州到泰国物流公司-泰廊曼国际 | 贴片电容-贴片电阻-二三极管-国巨|三星|风华贴片电容代理商-深圳伟哲电子 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | ge超声波测厚仪-电动涂膜机-电动划格仪-上海洪富 | 合肥升降机-合肥升降货梯-安徽升降平台「厂家直销」-安徽鼎升自动化科技有限公司 | 杭州ROHS检测仪-XRF测试仪价格-百科 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 上海三信|ph计|酸度计|电导率仪-艾科仪器 | 药品仓库用除湿机-变电站用防爆空调-油漆房用防爆空调-杭州特奥环保科技有限公司 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 红外光谱仪维修_二手红外光谱仪_红外压片机_红外附件-天津博精仪器 | 代做标书-代写标书-专业标书文件编辑-「深圳卓越创兴公司」 | CCE素质教育博览会 | CCE素博会 | 教育展 | 美育展 | 科教展 | 素质教育展 | 防爆鼓风机-全风-宏丰鼓风机-上海梁瑾机电设备有限公司 | 电动高压冲洗车_价格-江苏速利达机车有限公司 | 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | 台湾Apex减速机_APEX行星减速机_台湾精锐减速机厂家代理【现货】-杭州摩森机电 | 深圳公司注册-工商注册公司-千百顺代理记账公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 工业CT-无锡璟能智能仪器有限公司| 24位ADC|8位MCU-芯易德科技有限公司| 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | 涂层测厚仪_光泽度仪_uv能量计_紫外辐照计_太阳膜测试仪_透光率仪-林上科技 | 东亚液氮罐-液氮生物容器-乐山市东亚机电工贸有限公司 |