我有一个列表,我为此编写了一个自定义适配器。我想为此设置一些文本颜色(例如橙色代码#F06D2F)。我正在展示我的 getView()
方法的代码 fragment 。
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);
问题是我看不到设置为橙色的颜色。出了什么问题?
注意:上下文在构造函数和对象(字符串数组)中传递
感谢您的帮助
最佳答案
尝试这样,以下对我来说很好用
textview.setTextColor(this.getResources().getColor(R.color.orange));
关于Android从java代码设置 TextView 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4499208/