在strings.xml中存储十六进制颜色值颜色、strings、xml、十六进制

2023-09-06 01:26:02 作者:袖手天下メ只为你

我想保存十六进制颜色我在strings.xml中的文本值,因此,所有的布局文件将涉及到(要能快速改变一切布局文本项目很容易),但是我无法引用它。

I'm trying to store the hex color value of my text in strings.xml so all the layout files will refer to that (to be able to quickly change all layout text for the project easily) however I'm having trouble referring to it.

使用安卓文字颜色=#FFFFFF在我的XML布局工作正常。但是使用安卓文字颜色=@字符串/文字颜色给我一个错误既当我包括#和没有包括。

Using android:textColor="#FFFFFF" in my xml layout works fine. However using android:textColor="@strings/textColor" gives me an error both when I include a # and not include.

当我不包括它要求的#的#。当我做加#DDMS报道:

When I don't include the # it asks for the #. When I do add the # DDMS reports:

4月7号至13号:35:22.870:ERROR / AndroidRuntime(331):由:android.content.res.Resources $ NotFoundException:文件#FF0000从绘制资源ID#0x7f040003:需要.xml扩展

07-13 04:35:22.870: ERROR/AndroidRuntime(331): Caused by: android.content.res.Resources$NotFoundException: File #FF0000 from drawable resource ID #0x7f040003: .xml extension required

有谁知道我可以在布局文件合并报表?例如,文字颜色=#+@字符串/文字颜色,然后只设置字符串FFFFFF例如

Does anyone know how I can combine statements in the layout file? eg textColor="#"+"@strings/textColor and then just set the string to "FFFFFF" for example.

推荐答案

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

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

<color name="gray">#eaeaea</color>
<color name="titlebackgroundcolor">#00abd7</color>
<color name="titlecolor">#666666</color>

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

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