How can I save colors in array.xml and get its back to Color[] array

后端 未结 8 1284
借酒劲吻你
借酒劲吻你 2020-12-04 21:01

How can I save color values inside array.xml and retrieve its back to my code as Color [] array?

Thanks beforehand!

8条回答
  •  旧时难觅i
    2020-12-04 21:38

    colors.xml

    
                
            #ff0000
            #00ff00  
            #0000ff
        
    
    

    Code in activity class.

    String[] allColors = context.getResources().getStringArray(R.array.colors);
    
    Color.parseColor(allColors[0]) // red
    Color.parseColor(allColors[1]) // green
    Color.parseColor(allColors[2]) // blue
    

提交回复
热议问题