Android get color as string value

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

If i defined a color in resources


    #123456

it\'s possible

11条回答
  •  太阳男子
    2021-01-30 19:57

    Just for the sake of easy copypasta:

    "#" + Integer.toHexString(ContextCompat.getColor(getActivity(), R.color.some_color));
    

    Or if you want it without the transparency:

    "#" + Integer.toHexString(ContextCompat.getColor(getActivity(), R.color.some_color) & 0x00ffffff);
    

提交回复
热议问题