如何让用户在android列表视图中选择主题?

2024-05-16

我有一个带有两个标签的列表视图,标题和副标题。我想要深色和浅色背景作为用户选项。标题具有 textAppearanceMedium,副标题具有 textAppearanceSmall。我希望样式 MyTheme.Dark 具有白色文本,MyTheme.Light 具有黑色文本。有没有办法为同一个 TextView 小部件定义多个 textAppearance 属性?

<style name="MyTheme.Dark">
    <item name="android:windowBackground">@color/black</item>
    <item name="android:colorBackground">@color/black</item>
    <item name="android:background">@color/black</item>
    <item name="android:divider">@color/white</item>
        --cannot put textAppearance here since it is different for title and subtitle
    </style>

备查...

在值/themes.xml中:

<style name="MyTheme.Dark">
    <item name="textColorTitle">@color/white</item>
</style>
<style name="MyTheme.Light">
    <item name="textColorTitle">@color/black</item>
</style>

在值/attrs.xml 中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr
        name="textColorTitle"
        format="reference|color" />
</resources>

在layout/my_list_row.xml中,使用textColorTitle值作为文本颜色,如下所示:

android:textColor="?textColorTitle"

如果不起作用请告诉我。这个对我有用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让用户在android列表视图中选择主题? 的相关文章

随机推荐