<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,可以設定字型顔色
加下劃線
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);
}
}
轉載:http://blog.csdn.net/chaoyu168/article/details/50698197