How to set the text color of TextView in code?

后端 未结 30 2642
你的背包
你的背包 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:23

    TextView text = new TextView(context);
    text.setTextColor(Color.parseColor("any hex value of a color"));
    

    Above code is working on my side. Here text is a TextView on which color is needed to be set.

提交回复
热议问题