Android中EditText如何去除邊框添加下劃線
更新時間:2016年02月19日 16:58:57 作者:chaoyu168
這篇文章主要介紹了Android中EditText如何去除邊框添加下劃線的相關資料,需要的朋友可以參考下
廢話不多說了,直接給大家貼代碼了。
<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);
// 得到總行數(shù)
int lineCount = getLineCount();
// 得到每行的高度
int lineHeight = getLineHeight();
// 根據(jù)行數(shù)循環(huán)畫線
for (int i = 0; i < lineCount; i++) {
int lineY = (i + 1) * lineHeight;
canvas.drawLine(0, lineY, this.getWidth(), lineY, paint);
}
}
}
以上內容給大家介紹了Android中EditText如何去除邊框添加下劃線的相關內容,希望對大家有所幫助!
相關文章
Android 中動態(tài)加載.jar的實現(xiàn)步驟
本文介紹動態(tài)加載 .jar的實現(xiàn)步驟,這將對你的android開發(fā)很有幫助,剛興趣的朋友可以了解下哦2013-01-01

