How to set the text color of TextView in code?

后端 未结 30 3027
你的背包
你的背包 2020-11-22 07:48

In XML, we can set a text color by the textColor attribute, like android:textColor=\"#FF0000\". But how do I change it by coding?

I tried s

30条回答
  •  深忆病人
    2020-11-22 08:33

    Similarly, I was using color.xml:

    #ffffff
        #000000   
    

    For setting the TextView background like:

    textView.setTextColor(R.color.white);
    

    I was getting a different color, but when I used the below code I got the actual color.

    textView.setTextColor(Color.parseColor("#ff6363"));
    

提交回复
热议问题