I'm just a beginner with Android. I want the button to change its color on mouseover.
I don't know how to do that in android. Can it be done?
View for a button:
<Button
android:id="@+id/b8"
android:text="click me"
style="?android:attr/buttonStyleSmall"
android:textSize="20dp" />
To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.
Type background-color: in the quotation marks after "style=". This element is used to change the background color of the button. Type a color name or hexadecimal code after "background-color:". You can type name of a color (i.e, blue) or a hexadecimal color.
The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.
You need to use what's called a selector
.
You can read about them and get a tutorial from this site.
Keep in mind that there really isn't a concept in Android as "hover" since you can't hover your finger over the display. But you can create selectors for, say, when a button has focus. Normally a button can have three states: Normal, Focused and Pressed.
The particular mouse hover functionality as we know it, is supported on Android OS 4.0 and above. Views have onHoverListeners(). Isnt it finally great
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With