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);
精彩评论