Search code examples
javaandroid-studiobuttonbackground-coloramazon-fire-tv

How to Change Color of Button when FireTV remote navigates over it


I am making my first Android App. This is for a firestick. All done except for the color of the buttons. The default light gray color is good enough (though I may change this when I find out how to). When navigating over buttons with the remote control, the color of the button only changes to a slightly darker color. It makes it near impossible to tell which button is being navigated over. I have gone all through the code and can find nowhere to change this to a darker color. Changing just the background color stops the color changing at all when it is navigated over. Where would I change this color?


Solution

  • As luck would have it I managed to find the answer just after I posted. Create xml file in drawable (I used button_events.xml):

    <?xml version="1.0" encoding="utf-8"?>
    <selector
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:state_focused="true"
            android:drawable="@color/primary_dark"/>
        <item
            android:state_pressed="true"
            android:drawable="@color/primary_dark"/>
        <item android:drawable="@color/primary" />
    </selector>
    

    Then I set my buttons background to use this drawable:

    <Button
        android:background="@drawable/button_events"/>