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

3

编辑:我的AndroidManifest中的代码有误,应该是

android:theme="@style/CustomTheme" 

现在所有文本颜色都已更改。不是按钮颜色,但我正在努力。感谢您的帮助。
这应该是个简单的问题,但我一直收到错误。据我所知,我正在按照安卓文档此处的说明操作,但它不起作用。我在这个问题上阅读了很多stackoverflow线程,并试图遵循看起来最好的那个。目标是在已经完成的项目中全局更改文本颜色。
这在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"一行生成了一个错误,然后导致每个类都出现错误。

我认为这并不像那么容易。如果你看一下内置主题,你会发现每种组件的文本颜色都有定义。 - Lionel Port
看一下这个 style.xml,了解每个样式是如何定义文字颜色的。https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml 。有时它是继承的,有时它是一个属性,有时它只是硬编码。 - Lionel Port
也许我需要让父级为TextAppearance.Large,因为我的所有文本都是这种风格。但是那么如何使Theme.Black成为主题呢? - Allen Edwards
如果您查看Holo主题的定义方式,那么它应该是一个合理的示例。基本上,它扩展了默认行为并定义了一个新的Holo特定版本。例如:<style name="TextAppearance.Holo.Large" parent="TextAppearance.Large"></style> - Lionel Port
我想我需要一个将所有内容与应用程序结合起来的示例参考。我应该在AndroidManifest中放什么,以及我应该把哪些文件放在哪里。恐怕我还没有理解清楚。 - Allen Edwards
感谢 @LionelPort 的帮助。请查看我的答案。只是一个愚蠢的错误。 - Allen Edwards
1个回答

3
我离成功很近,只是一个打字错误,但由于我在网上找不到答案,而且发现有很多人在询问,所以我想记录下最终有效的解决方法。这种方法并不能解决硬编码颜色的情况,但我也不指望它能做到。这种方法可以改变所有默认文本颜色。
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"

那是另一个故事,我需要编辑每个实例来更改它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接