gpt4 book ai didi

android - 如何使用自定义主题更改默认文本颜色?

转载 作者:IT王子 更新时间:2023-10-28 23:40:24 29 4
gpt4 key购买 nike

我正在尝试的主题应该很容易,但我不知道如何:我希望我的应用程序中的所有文本默认为白色。我在 theme.xml 中创建了一个自定义主题:

<style name="Theme" parent="@android:Theme">
</style>

<style name="TextAppearance.Theme" parent="@android:TextAppearance.Theme">
<item name="android:textColor">#ffffffff</item>
</style>

并为整个应用程序设置它:

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

但标签仍然是黑色的。缺少什么?

PS:如何为不同的文本大小另外定义样式,以应用于每个小部件?这样的事情对吗?

<style name="Theme.smallText">
<item name="android:textSize">12dp</item>
</style>

更新

我查看了 Android SDK 中的 themes.xml,它展示了如何为主题设置文本样式:

<item name="textAppearance">@android:style/TextAppearance</item>

在我的情况下,它应该适用于这个定义:

<style name="Theme" parent="@android:Theme">
<item name="android:textAppearance">@style/MyText</item>
</style>

<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#ffffffff</item>
</style>

但是还是不行。

这里是 another post关于同样的问题。

最佳答案

在您的 Manifest 中,您需要引用其中包含文本颜色 itemstyle 的名称。现在你只是在引用一个空的 style。所以在你的 theme.xml 中只做这个 style:

<style name="Theme" parent="@android:style/TextAppearance">
<item name="android:textColor">#ffffffff</item>
</style>

并且让你在Manifest中引用的一样(android:theme="@style/Theme")

编辑:

主题.xml:

<style name="MyTheme" parent="@android:style/TextAppearance">
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">12dp</item>
</style>

list :

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

请注意,我将文本颜色和大小组合到相同的 style 中。此外,我将主题的名称更改为 MyTheme,现在在 Manifest 中引用它。我将 parent 值更改为 @android:style/TextAppearance

关于android - 如何使用自定义主题更改默认文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9593133/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com