Convert hex color value ( #ffffff ) to integer value

前端 未结 9 1068
孤城傲影
孤城傲影 2020-12-13 01:26

I am receiving hex color values from a server (in this form, #xxxxxx , example #000000 for black)

How do I convert this to an integer value

9条回答
  •  清歌不尽
    2020-12-13 01:46

    I was facing the same problem. This way I was able to solved it. As CQM said, using Color.parseColor() is a good solution to this issue.

    Here is the code I used:

    this.Button_C.setTextColor(Color.parseColor(prefs.getString("color_prefs", String.valueOf(R.color.green))));
    

    In this case my target was to change the Button's text color (Button_C) when I change the color selection from my Preferences (color_prefs).

提交回复
热议问题