Question

i'm using simple button with its background colored as like -

android:background="#FF58585A" 

but now it'll not appear to touchable or clickable can anyone help me how i make this button touchable.

Was it helpful?

Solution

U need to add selector (in your drawable folder) as your background

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/normal" android:state_enabled="false"/>
<item android:drawable="@color/pressed" android:state_pressed="true"/>
<item android:drawable="@color/pressed" android:state_focused="true"/>
<item android:drawable="@color/pressed" android:state_selected="true"/>
<item android:drawable="@color/normal"/>
</selector>

Your values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="normal">#FF58585A</color>
    <color name="pressed">#ffffff</color> // what ever pressed value u want
</resources>

Then set this selector as your button background

    android:background="@drawable/btn_selector"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top