Android a method for implementing EditText underline in multiple lines

Source: Internet
Author: User

1. Rewrite EditText

 Public classLinededittext extends EditText {PrivatePaint Linepaint; Private floatmargin; Private intPapercolor;  PublicLinededittext (Context paramcontext, AttributeSet paramattributeset) {super (Paramcontext, Paramattributeset)         ;  This. Linepaint =NewPaint (); }      protected voidOnDraw (Canvas paramcanvas) {Paramcanvas.drawcolor ( This. Papercolor); inti =Getlinecount (); intj =getheight (); intK =getlineheight (); intm =1+ J/K; if(I <m) I=m; intn =Getcompoundpaddingtop (); Paramcanvas.drawline (0.0F, N, GetRight (), N, This. Linepaint);  for(intI2 =0;; i2++) {             if(I2 >=i) {setpadding (Ten+ (int) This. Margin,0,0,0);                 Super.ondraw (Paramcanvas);                 Paramcanvas.restore (); return; } N+=K; Paramcanvas.drawline (0.0F, N, GetRight (), N, This. Linepaint);         Paramcanvas.save (); }     }  }

This code is not complicated without comments, students who have learned Java should not have the difficulty.

2. Using in the layout file

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="match_parent"Android:layout_height="match_parent"android:orientation="Vertical"> <Com.example.storetest.LinedEditText Android:id="@+id/et1"Android:layout_width="fill_parent"Android:layout_height="200DP"android:gravity="Top"Android:inputtype="Textmultiline"/> </LinearLayout>

Note: When using the EditText control, the EditText prefix is no longer used, but instead the package name + class name (such as Com.example.storetest.LinedEditText) of the full path after overriding.

3. When used in accordance with normal call EditText.

Android a method for implementing EditText underline in multiple lines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.