Android get color as string value

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

If i defined a color in resources


    #123456

it\'s possible

11条回答
  •  隐瞒了意图╮
    2021-01-30 19:45

    If you don't want to use ContextCompat or SuppressLint, simply add a string resource right under your color.

    Instead of

    #FFFFFF
    

    Use

    #FFFFFF
    #FFFFFF
    

    Your code does get more repetitive but it's much cleaner. Besides, forgeting to updating the string after changing color is almost impossible since they are right next to each other.

提交回复
热议问题