简体   繁体   中英

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

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)
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. When an activity loads, use a ThemeSettings object with SharedPreferences to set your button drawable based on your user preference. You need an XML for each drawable option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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