Android get color as string value

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

If i defined a color in resources


    #123456

it\'s possible

11条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 20:02

    Cause getResources().getColor need api > 23. So this is better: Just for the sake of easy copy & paste:

    Integer.toHexString( ContextCompat.getColor( getContext(), R.color.someColor ) );

    Or if you want it without the transparency:`

    Integer.toHexString( ContextCompat.getColor( getContext(), R.color.someColor ) & 0x00ffffff );

提交回复
热议问题