Reputation: 61
Is there anyway to change the appearance of a button when the user clicks on it? for example change the color or make it dark? Like using CSS in ASP.net to hover over a word or a link.
Upvotes: 1
Views: 4689
Reputation: 6487
Try this. Save this as a drawable xml resource and set this as a background of your button. Please explore the other options of Selector class.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"><shape>
<gradient android:angle="270" android:endColor="#BB908C8B" android:startColor="#BB908C8B" />
<corners android:bottomLeftRadius="9dp" android:topRightRadius="9dp" />
</shape></item>
<item android:state_pressed="true"><shape>
<gradient android:angle="270" android:endColor="#BB54504F" android:startColor="#BB54504F" />
<corners android:bottomLeftRadius="9dp" android:topRightRadius="9dp" />
</shape></item>
</selector>
Look at the link http://android.onyou.ch/2011/01/25/simple-custom-button-using-a-selector-xml-layout/
Upvotes: 1