Android get color as string value

前端 未结 11 1499
青春惊慌失措
青春惊慌失措 2021-01-30 19:28

If i defined a color in resources


    #123456

it\'s possible

11条回答
  •  佛祖请我去吃肉
    2021-01-30 19:37

    For API above 21 you can use

    getString(R.color.color_name);
    

    This will return the color in a string format. To convert that to a color in integer format (sometimes only integers are accepted) then:

    Color.parseColor(getString(R.color.color_name));
    

    The above expression returns the integer equivalent of the color defined in color.xml file

提交回复
热议问题