当 FireTV 遥控器在按钮上导航时如何更改按钮的颜色

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

我正在制作我的第一个 Android 应用程序。这是为了火棍。 除了按钮的颜色外,其他都已完成。 默认的浅灰色就足够了(尽管我可能会在了解如何更改时更改它)。 使用遥控器在按钮上导航时,按钮的颜色只会变为稍微深一点的颜色。这使得几乎无法判断正在导航哪个按钮。 我已经完成了所有代码,找不到任何地方可以将其更改为更深的颜色。 仅更改背景颜色会在浏览时完全停止颜色更改。 我要在哪里更改此颜色?

幸运的是,我在发布后就找到了答案。 在 drawable 中创建 xml 文件(我使用 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>

然后我将按钮背景设置为使用此可绘制对象:

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