當我禁用 TextInputLayout 時
InputTextContainer.isEnabled = false
它變灰了,所以在視覺上你明白它不可用,但即使它也被阻止,其中的文字仍然是黑色的。我希望我的文本作為禁用的容器呈灰色。你能幫我做嗎?
uj5u.com熱心網友回復:
使用默認主題,當您禁用 TextInputLayout 時,TextInputLayout 包含的 EditText 中的文本也會變灰。您可能在您的 EditText 上的主題或特定樣式中做了一些覆寫了它的操作。
例如,如果您指定了這樣的文本顏色:
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
tools:hint="Hint"
tools:text="Text" />
...您指定了一種不能對視圖的不同狀態做出反應的顏色。這里我定義了 black #000000,所以無論如何文本都是黑色的。
如果您想要一種在禁用時變為灰色或透明的顏色,您需要在 XML 中定義一個ColorStateList 顏色并將其用作您的android:textColor. 確保 ColorStateList 至少有一個與 對應的狀態state_enabled="false"。例如:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:color="#80000000"
android:state_enabled="false"/> <!-- Translucent black for disabled state -->
<item
android:color="#FF000000"/> <!-- Default -->
</selector>
uj5u.com熱心網友回復:
假設這是您的 xml 視圖
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/pswrd"
.....>
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/pswrd_text"
....>
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
你可以嘗試兩件事:
- 與設定的不同
pswrd.isEnabled = false,設定pswrdText.isEnabled=false為好。 - 如果 1 不起作用,請嘗試
pswrdText.setTextColor(android.R.color.darker_gray)
uj5u.com熱心網友回復:
就像@Nitin Verma 回答的那樣嘗試這種方法。
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/edt_email">
<TextView
android:id="@ id/textView20"
android:layout_width="wrap_content"/>
<com.google.android.material.textfield.TextInputEditText/>
edt_email.isEnable = false
textView20.isEnable = false
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/353692.html
