Issue
I have a simple Button, which has a drawable set as icon:
<Button
android:id="@+id/bOk"
android:drawableStart="@drawable/icon_ok"
android:text="@string/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
when I disable the button, either in XML layout file: android:enabled="false"
or programmaticaly: bOk.setEnabled(false);
The button gets disabled, it is 'grayed out', but the icon remains as it was ine the enabled state.
How can I get a look, that the icon is also 'grayed out'?
Solution
Create a new grayed icon and add both inside a selector.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_ok" android:state_enabled="true" />
<item android:drawable="@drawable/icon_ok_disabled" android:state_enabled="false" />
</selector>
Use inside button like: android:drawableStart="@drawable/selector"
For TextColor,
Create another selector inside res/color/mycustomtextcolor.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#666" android:state_enabled="false" />
<item android:color="#000" android:state_enabled="true"/>
</selector>
Inside your widget call using: android:textColor="@color/mycustomtextcolor"
Or
inside your style
add another item using: <item name="android:textColor">@color/mycustomtextcolor</item>
Answered By - Firoz Memon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.