Hello. Let me have a Button. After clicking on it, it is not clear whether it was pressed successfully. To make it clear to the user, in almost all applications after clicking on the Button, its color changes a little and becomes the same again, letting the user know that the button was successfully pressed. The question is how to do it? Hope there is some kind of Button function?
1 answer
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@android:color/black" /> //нажата <item android:drawable="@android:color/white" /> //обычно </selector>
In case the buttons have their own pictures:
new_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed_yellow" android:state_pressed="true" /> <item android:drawable="@drawable/button_focused_orange" android:state_focused="true" /> <item android:drawable="@drawable/button_normal_green" /> </selector>
Button:
<Button android:id="@+id/imageButtonSelector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/new_button" />
If I understood correctly, then something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" >//нажата <shape> ... </shape> </item> <item>//обычно <shape> ... </shape> </item>
- I have such a situation that for all the Button's in my application, I use buttonshape.xml, where the forms for the Button are written. I added your code there, but it does not work. What could be the problem? - abay
- @ andy11 updated the answer, I hope it helps - iFr0z
|