开发者

How to dynamically give color to Text

开发者 https://www.devze.com 2023-03-16 16:25 出处:网络
How to give color to text to dynamically created Textview ? TextView b3 = new TextView(this); b3.setLayoutParams(new

How to give color to text to dynamically created Textview ?

TextView b3 = new TextView(this); b3.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_C开发者_开发百科ONTENT));

b3.setTextSize(t);

      b3.setBackgroundColor(#000);


you can do one thing define your color inside the color.xml file as:

<color name="demo_color">#E01B4C</color>

And then access it as below:

b3.setTextColor(R.color.demo_color);


This one works

TextView b3 = new TextView(this); b3.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

b3.setTextSize(t);

      b3.setBackgroundColor(Color.BLACK);

You cant give # codes directly in the code.


try this method :

b3.setTextColor(Color.BLUE);


b3.setBackgroundColor(#000); => b3.setBackgroundColor(0); or even b3.setBackgroundColor(0x000);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号