简体   繁体   English

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

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

I am making my first Android App.我正在制作我的第一个 Android 应用程序。 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?我会在哪里改变这种颜色?

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):在 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>

Then I set my buttons background to use this drawable:然后我设置我的按钮背景来使用这个 drawable:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM