这里有新鲜出炉的精品教程,程序狗速度看过来!
Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。
这篇文章主要介绍了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);
- // 得到总行数
- 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如何去除边框添加下划线的相关内容,希望对大家有所帮助!
来源: http://www.phperz.com/article/17/0914/348970.html