从Java code Android的设置文本视图颜色 [英] Android setting text view color from java code
本文介绍了从Java code Android的设置文本视图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名单,我写这个自定义适配器。我想设置一些文本颜色为这个(如橙色code#F06D2F)。我是presenting的code段为我的 getView()
方法。
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)
感谢您的帮助
推荐答案
试试这样,下面的工作对我很好
try like this , the following worked fine for me
textview.setTextColor(this.getResources().getColor(R.color.orange));
这篇关于从Java code Android的设置文本视图颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文