Set Text Color for textView Android

后端 未结 8 1849
梦谈多话
梦谈多话 2021-02-06 03:41

In the string.xml file i use the following tag

 \"#0000ff\"

If I use

 textview         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 03:53

    I am basically just merging all the partially good answers.

    You defined your color as a String, but AFAIK Android processes colors as Itegers.
    So use the Colors.xml file (instead of strings.xml): and refer to it in code as R.color.CodeColor.
    (Moreover, I think, there is some naming convention that tells you to name these values all lowercase: code_color or codecolor)

    Or you can define them as strings, but then you are need to make it an Integer: Color.parseColor(R.string.code_color).

提交回复
热议问题