Issue
I have some buttons which I set its background color as red, green and blue separately. When I press the button, click event is generated, but there is no change in gui for the user to know the button is pressed. Android button’s default background grayish color changes to orange and come back to grayish color after releasing the pressed state. How to implement this on colored button?
Solution
That is implemented via a StateListDrawable
, represented by selector
in XML. Reference: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
Here is an example of a drawable that will be white by default, black when pressed:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@android:color/black" /> <!-- pressed -->
<item android:drawable="@android:color/white" /> <!-- default -->
</selector>
Answered By - K-ballo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.