Hover button color

I'm just new to Android. I want the button to change its color on the mouse.
I do not know how to do this in Android. It can be done?

View Button:

<Button android:id="@+id/b8" android:text="click me" style="?android:attr/buttonStyleSmall" android:textSize="20dp" /> 
+6
source share
4 answers

You need to use what is called a selector .

You can read about them and get a tutorial from this site.

Keep in mind that in Android there really is no such thing as a β€œfreeze” because you cannot point your finger at the screen. But you can create selectors, for example, when the button has focus. Typically, a button can have three states: Normal, Focused, and Pressed.

+2
source

Certain mouse functionality, as we know it, is supported in Android 4.0 and above. Views have onHoverListeners (). Isn't that wonderful?

+3
source

Here is the xml-- hover.xml -

 <item android:drawable="@drawable/image__hover" android:state_focused="false" android:state_pressed="true"/> <item android:drawable="@drawable/normalimage"/> 

and how do I use it in Button to change color when hovering

 <Button android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/hover" ></Button> 
+1
source

On Android, freezing is possible: all devices on which there is a track ball or D-pad keys or QWERTY keyboard can move the "freeze" or focus on everything that can be pressed (you can click). Then, for example, on my G1, you press the track ball to push it to the android:state_pressed .

0
source

Source: https://habr.com/ru/post/915440/


All Articles