Saturday 15 September 2012

android - Can I define multiple ColorStateLists in a single XML file? -


I have too many controls in my app, which should change its text color when changing the color line. Android offers a way to do it - color state list. For each color state list, I will have to create a separate XML file, such as:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Selector xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: color = "# 398ede" Android: state_pressed = "true" /> & Lt; Item Android: color = "# 808080" /> & Lt; / Selector & gt;   

Is there any way to avoid creating a separate file for each color state list and define them all in one file?

You may have found the answer by now, but those who come back to this link, So how do we do this.

If you have a resource file defining several such colors:

    

You should put this file under the values ​​(and not in the colors) to use the values ​​you use:

  dummy_button_id .setBackgroundColor (getResources () .getColor (R.color.xBlack));    

No comments:

Post a Comment