本文介紹了如果 EditText inside 被禁用,如何更改 TextInputLayout 的浮動提示顏色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我將 EditText
與 TextInputLayout
一起使用.如果 EditText 被禁用,我只想更改 TextInputLayout
的浮動提示顏色.我嘗試使用選擇器它不起作用.
I am using EditText
with TextInputLayout
. I just want to change the floating hint color of TextInputLayout
if the EditText is disabled. I tried with selector it is not working.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:textColor="@color/darkGray" />
<item android:state_pressed="false" android:state_focused="false" android:textColor="@color/lightGray"/>
</selector>
推薦答案
在 TextInputLayout
類中有一個名為 setHintTextAppearance(int styleId)
的方法.您可以使用此方法根據啟用/禁用狀態設置不同的顏色以提示文本.
There's one method called setHintTextAppearance(int styleId)
in TextInputLayout
class. You can use this method to set difference colors to hint text on basis of enabled/disabled state.
例子:
//for disabled editText
mEditText.setEnabled(false);
mTextInoutLayout.setHintTextAppearance(R.style.CustomHintDisabled);
//for enablededitText
mEditText.setEnabled(true);
mTextInoutLayout.setHintTextAppearance(R.style.CustomHintEnabled);
在你的 styles.xml
<style name="CustomHintDisabled" parent="YourBaseTheme.TextAppearance">
<item name="textColor">@color/gray</item>
</style>
<style name="CustomHintEnabled" parent="YourBaseTheme.TextAppearance">
<item name="textColor">@color/black</item>
</style>
這篇關于如果 EditText inside 被禁用,如何更改 TextInputLayout 的浮動提示顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!