Android setting text view color from java code

2020-06-01 05:06发布

I have a list and i write a custom adapter for this. And I want to set some text color for this (e.g. Orange color code #F06D2F). I am presenting the code snippet for my getView() method.

TextView text = new TextView(this.context);
// text.setPadding(25, 5, 0, 0);

text.setBackgroundResource(R.drawable.back_horizontal);

// text.setClickable(false);
// text.setFocusable(false);
text.setEllipsize(TruncateAt.END);
text.setSingleLine(true);

// text.setTextColor(R.color.yellow);

text.setTextColor(R.color.Orange);
text.setGravity(Gravity.CENTER_VERTICAL);


helvetica_normal = Typeface.createFromAsset(context.getAssets(), "fonts/helvetica.ttf");

text.setTypeface(helvetica_normal);
// text.setTextColor(R.color.yellow);



text.setText(objects[position]);

LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
manager.addView(text, layoutParams);

The problem is that i can't see the color set to orange. What went wrong?

Note: The context is passed in constructor as well as objects (the string array)

Thanks for your help

8条回答
欢心
2楼-- · 2020-06-01 05:56
text.setTextColor(Color.parseColor("#FFFFFF"));
查看更多
走好不送
3楼-- · 2020-06-01 06:01

You Can also use text.setTextColor(0xFFF06D2F);
but not just text.setTextColor(0xF06D2F);

查看更多
登录 后发表回答