android
="http://schemas.
android
.com/apk/res/
android
">
<corners
android
:radius="20dp"/>
<solid
android
:co.
我们在实际项目经常遇到
EditText
输入框输入的时候底部
横线
需要变色或加粗的情况,本来网上有很多种方法都可以设置,但博主在实际搬砖中却出现了各种问题:
方法一:在styles.xml中设置
<style name="My
EditText
" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/color_normal</item>//默认颜色
怎样实现带有横栏的
EditText
(像记事本的编辑界面那样)?
(二)初步思路
1.通过修改
EditText
背景来实现(系统背景是一个框形图片,内部透明,替换为一个带有横栏的图片即可)
2.通过重绘
EditText
来实现(自定义组件,自己画线)
3.用ListView实现(ListView本身就会显示
横线
)
(三)深入分析
1.
EditText
显示多行文本时会自动拉伸背景...
有的时候需要隐藏掉
EditText
的边框和下划线,代码为:
主要是这一栏:
android
:background="@null"<
EditText
style="?
android
:attr/textViewStyle"
android
:layout_width="wrap_content"
android
:layout_heig
因设计的需求有时我们不得不改变
EditText
底线颜色,接下来我们就实现
EditText
改变光标及底线颜色:一.
EditText
未做任何设置之间效果:
xml.layout:
<
EditText
android
:hint="
EditText
未做任何设置"
android
:layout_width="match_parent"
android
:...
要
去掉
Android
EditText
的下划线,可以使用以
下方
法:
1. 在XML布局文件中,将
EditText
的属性
android
:background设置为透明色或其他颜色,例如:
<
EditText
android
:id="@+id/
editText
"
android
:layout_width="match_parent"
android
:layout_height="wrap_content"
android
:background="@
android
:color/transparent" />
2. 在Java代码中,使用
EditText
的方法setBackgroundColor()将背景颜色设置为透明色或其他颜色,例如:
EditText
editText
= findViewById(R.id.
editText
);
editText
.setBackgroundColor(Color.TRANSPARENT);
这样就可以
去掉
EditText
的下划线了。