How to set the text color of TextView in code?

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

    if you want to give color code directly then use

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

    or if you want to give color code from colors folder then use

    textView.setTextColor(R.color.white);
    

提交回复
热议问题