简体   繁体   English

按下按钮时更改颜色列表项的值

[英]change color list item's value when a button is pressed

In my android app text colors of buttons are defined in a "color state list " xml file called buttoncolor.xml 在我的Android应用程序中,按钮的颜色在名为“ colorcolor.xml”的“颜色状态列表” xml文件中定义

what I'm tryin to do is to change the theme of the app from green to blue with a click of button 我正在尝试做的是通过单击按钮将应用程序的主题从绿色更改为蓝色
so when the user clicks,color value of the buttoncolor.xml file changes from green ("#4CD964") to blue ...forever (it doesn't matter if it's done from xml or java) 因此,当用户单击时,buttoncolor.xml文件的颜色值会从绿色(“#4CD964”)永久更改为蓝色(无论是从xml还是从java完成)
Here's my code 这是我的代码

     <?xml version="1.0" encoding="utf-8"?>

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:color="#4CD964"
            android:state_pressed = "true"
        />
        <item
            android:color="@android:color/darker_gray"
        />
    </selector>

How can I Achieve this ? 我该如何实现?

You don't need to change the XML. 您无需更改XML。 When an activity loads, use a ThemeSettings object with SharedPreferences to set your button drawable based on your user preference. 加载活动时,可将ThemeSettings对象与SharedPreferences一起使用,以根据用户偏好设置按钮可绘制。 You need an XML for each drawable option. 每个可绘制选项都需要一个XML。

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

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