当前位置: 移动技术网 > IT编程>移动开发>Android > Android更改EditText下划线颜色样式的方法

Android更改EditText下划线颜色样式的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

福州汽车站网上售票,叶选平女婿黄华华,张允静

前言

相信大家都知道,当使用appcompatedittext(edit text)时,默认的下划线是跟随系统的#ff4081的颜色值的,通过改变这个值可以改变所有的颜色样式

有时候你想单独定义某一个界面的颜色样式,则可以这样做:

1.在你的build.gradle中添加最新的appcompat库

dependencies { 
 compile 'com.android.support:appcompat-v7:x.x.x' // x.x.x 为最新的版本号
 }

2.让你的activity继承android.support.v7.app.appcompatactivity

public class mainactivity extends appcompatactivity {
 ...
}

3.在任何layout.xml文件中声明您的edittext

<edittext 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:hint="hint text"/>

4.在styles.xml文件中声明自定义样式

<style name="myedittext" parent="theme.appcompat.light"> 
 <item name="colorcontrolnormal">@color/indigo</item> 
 <item name="colorcontrolactivated">@color/pink</item>
</style>

5.通过android:theme属性将此样式应用于您的edittext

<edittext 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:hint="hint text" 
 android:theme="@style/myedittext"/>

效果如下:

总结

以上就是关于android更改edittext下划线颜色样式的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网