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