在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的!
控制如下:
- @color/colorPrimary
- @color/colorPrimaryDark
**- @color/colorPrimaryDark
**
所以,只需要修改colorAccent的颜色,其下划线的颜色既可以修改!
在低版本和高版本中,同样是可以去添加下划线的!方法有二:
方法一:
//此时必须要设置其背景为空
//资源名称为 drawable/line
方法二:通过自定义editText
public class UnderLineEditText extends EditText {
private Paint paint;
public UnderLineEditText(Context context, AttributeSet attrs) {
super(context, attrs);
//设置画笔的属性
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
//设置画笔颜色为红色
paint.setColor(Color.RED);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawLine(0, this.getHeight()-2, this.getWidth()-2, this.getHeight()-2, paint);
}
}
这里有几点需要注意:
其一:也可以继承android.support.v7.widget.AppCompatEditText,但是有时会出现获取不到焦点的现状
其二:下划线的的位置确定
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



