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

后端 未结 8 1281
借酒劲吻你
借酒劲吻你 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:34

    In Kotlin that will be much simpler

     val colors = resources.obtainTypedArray(R.array.colors).use { ta ->
         IntArray(ta.length()) { ta.getColor(it, 0) }
     }
    

提交回复
热议问题