这篇文章主要介绍了Android中EditText如何去除边框添加下划线的相关资料,需要的朋友可以参考下
这篇文章主要介绍了Android中EditText如何去除边框添加下划线的相关资料,需要的朋友可以参考下
这篇文章主要介绍了Android中EditText如何去除边框添加下划线的相关资料,需要的朋友可以参考下
废话不多说了,直接给大家贴代码了。
|
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); } @overrideprotected 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如何去除边框添加下划线的相关内容,希望对大家有所帮助!
发表评论