使用新样式全局更改文本颜色

时间:2013-06-07 02:37:12

标签: android android-layout

编辑:我在AndroidManifest中的界限是错误的。应该是

android:theme="@style/CustomTheme" 

现在所有文字颜色都已更改。不是按钮颜色,但我正在路上。谢谢您的帮助。


这一定是一个简单的答案,但我一直都会遇到错误。据我所知,我遵循Android文档HERE,但它不起作用。我已经在这个问题上阅读了许多stactoverflow线程,并试图遵循看起来最好的一个。目标是在已经完成的项目中全局更改文本颜色。

这是在res / values / styles.xml

<resources>
    <style name="style_name" parent="@android:style/Theme.Black">
        <item name="android:textColor">#00FF00</item>
    </style>
</resources>

我在AndoridMinafest.xml中引用它

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/style_name" 
    >

我要做的是保持Theme.Black的基本风格,但改变文字颜色。

我做错了什么? AndroidManifest中的android:theme =“@ android:style / style_name”行生成一个错误,然后错误输出每个类。

1 个答案:

答案 0 :(得分:1)

我很接近,只是一个错字但由于我无法在网上找到答案,发现很多人都在问我以为我会准确记录最终起作用的内容。这对我硬编码颜色的情况不起作用,但我不希望发生这种情况。这确实改变了所有默认文本颜色。

AndroidManifest被修改如下:

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" 
     >

文件res / values / styles.xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomTheme" parent="android:Theme.Black">
        <item name="android:textColor">#ffff00</item>
    </style>
</resources>

这很有效。所有文本都是黄色的 - 除了定义为

的文本
android:textColor="@android:color/white"

这是另一个故事。我将不得不编辑每个实例来改变它。