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

后端 未结 8 1212
借酒劲吻你
借酒劲吻你 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条回答
  •  有刺的猬
    2020-12-04 21:27

    Color.xml:

     
            #448AFF
            #FFC107
            #009688
            #ff8000
            #ffbf00
            #0000ff
            #936c6c
            #7733ff
            #7733ff
            #ff8000
            #448AFF
            #0000ff
        
    

    activity.java file

    Context context;
     String[] colors = context.getResources().getStringArray(R.array.listcolors);
    
     String bg_color = colors[i]; //i=1,2,3...
    

提交回复
热议问题