解決Android EditText 修改下劃線失效的問題

大家都知道怎麼修改EditText下劃線顏色的方法

樓主在實際項目中遇到EditText 修改下劃線失效,找了很久沒找到問題

偶然的情況下,我發現我的項目是支持androidx的

android.enableJetifier=true
android.useAndroidX=true

那麼只需要把

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyEditText" />

改爲

<androidx.appcompat.widget.AppCompatEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyEditText" />

就可以了

 

順便附上如何修改EditText下劃線顏色的方法:

styles.xml裏面加上

<style name="MyEditText" parent="Theme.AppCompat.Light">
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/black</item>
</style>

EditText標籤上加上

android:theme="@style/MyEditText"

就可以了

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章