Issue
When I disable my TextInputLayout
InputTextContainer.isEnabled = false
it's getting grey so visually you understand that it's unavailable but text in it still black even it's blocked too. I want my text to be grey as the disabled container. Can you help me to do that?
Solution
Using the default theme, the text in a TextInputLayout's contained EditText is also grayed out when you disable a TextInputLayout. You may have done something in your theme or specific styling on your EditText that has overridden this.
For example, if you have specified a text color like this:
<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" />
...you have specified a single color that cannot react to different states of the view. Here I defined black #000000
, so the text will be black no matter what.
If you want a color that turns gray or transparent when it's disabled, you need to define a ColorStateList color in XML and use that as your android:textColor
. Make sure the ColorStateList has at least one state that corresponds with state_enabled="false"
. For example:
<?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>
Answered By - Tenfour04