Android更改EditText下劃線顏色樣式的方法
前言
相信大家都知道,當使用AppCompatEditText(Edit Text)時,默認的下劃線是跟隨系統(tǒng)的#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下劃線顏色樣式的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
相關文章
Android實現調用系統(tǒng)圖庫與相機設置頭像并保存在本地及服務器
這篇文章主要介紹了Android實現調用系統(tǒng)圖庫與相機設置頭像并保存在本地及服務器 ,需要的朋友可以參考下2017-03-03
Android編程實現實時監(jiān)聽EditText文本輸入的方法
這篇文章主要介紹了Android編程實現實時監(jiān)聽EditText文本輸入的方法,結合實例形式分析了EditText控件及事件響應相關操作技巧,需要的朋友可以參考下2017-06-06
Android開發(fā)環(huán)境安裝和配置圖文教程
輕松搞定Android開發(fā)環(huán)境部署,這篇文章主要為大家詳細介紹了Android開發(fā)環(huán)境安裝和配置圖文教程,感興趣的小伙伴們可以參考一下2016-06-06
Android 中ListView setOnItemClickListener點擊無效原因分析
這篇文章主要介紹了Android 中ListView setOnItemClickListener點擊無效原因分析的相關資料,需要的朋友可以參考下2016-01-01

