廢話不多說了,直接給大家貼代碼了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<span style= "font-family: arial, helvetica, sans-serif;" ><?xml version= "1.0" encoding= "utf-8" ?> </span> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "fill_parent" > <!--注意名稱 --> <com.marine.study.lineedittext android:id= "@+id/myedit" android:layout_width= "fill_parent" android:layout_height= "wrap_content" style= "?android:attr/textviewstyle" android:background= "@null" android:textcolor= "@null" /> </linearlayout> |
其中background,可以設置成其他顏色等
textcolor不一定要是null,可以設置字體顏色
加下劃線
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
public class lineedittext extends edittext { // 畫筆 用來畫下劃線 private paint paint; public lineedittext(context context, attributeset attrs) { super (context, attrs); paint = new paint(); paint.setstyle(paint.style.stroke); paint.setcolor(color.red); // 開啟抗鋸齒 較耗內存 paint.setantialias( true ); } @override protected void ondraw(canvas canvas) { super .ondraw(canvas); // 得到總行數 int linecount = getlinecount(); // 得到每行的高度 int lineheight = getlineheight(); // 根據行數循環畫線 for ( int i = 0 ; i < linecount; i++) { int liney = (i + 1 ) * lineheight; canvas.drawline( 0 , liney, this .getwidth(), liney, paint); } } } |
以上內容給大家介紹了android中edittext如何去除邊框添加下劃線的相關內容,希望對大家有所幫助!