设置文本颜色的TextView的Andr​​oid [英] Set Text Color for textView Android

查看:140
本文介绍了设置文本颜色的TextView的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用下面的标记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:

<一个href="http://developer.android.com/guide/topics/ui/themes.html">http://developer.android.com/guide/topics/ui/themes.html

这篇关于设置文本颜色的TextView的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆