设置文本颜色的TextView的Andr​​oid文本、颜色、TextView、Andr

2023-09-05 07:35:19 作者:轻狂°hyperbole

在我使用下面的标记string.xml文件

In the string.xml file i use the following tag

 <string name="CodeColor" >"#0000ff"</string>

如果我用

 textview1.setTextColor(Color.RED);

它的工作原理,但是当我使用

it works, but when I use

  textview1.setTextColor(TextViewStyles.this.getResources().getColor(R.string.CodeColor)); 

 or
 textview1.setTextColor(R.string.CodeColor);

这doen't工作。 任何建议...

it doen't work. Any suggestions...

在此先感谢

推荐答案

您需要创建一套风格在你的XML(定期RES /价值/ styles.xml)

You need to create a set of styles in your xml (regularly in res/values/styles.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="gray">#eaeaea</color>
    <color name="titlebackgroundcolor">#00abd7</color>
    <color name="titlecolor">#666666</color>
<resources>

在布局文件,你可以打电话的颜色或样​​式:

In the layout files you can call to the colors or styles:

android:textColor="@color/titlecolor"

结帐的一些例子:

Checkout some examples:

http://developer.android.com/guide/topics/ui/themes.html