如何让用户在android列表视图中选择主题?
我有一个带有两个标签的列表视图,标题和副标题。我想要深色和浅色背景作为用户选项。标题具有 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>
I have a listview with two labels, title and subtitle. I want to have dark and light background as user options. Title has textAppearanceMedium and subtitle has textAppearanceSmall. I want the style, MyTheme.Dark to have white color text and MyTheme.Light to have black color text. Is there a way to define multiple textAppearance attribute for the same TextView widget?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
供将来参考...
在values/themes.xml中:
在values/attrs.xml中:
在layout/my_list_row.xml中,使用textColorTitle值作为文本颜色,如下所示:
如果它不起作用,请告诉我。这对我有用。
For future reference...
In values/themes.xml:
In values/attrs.xml:
In layout/my_list_row.xml, use textColorTitle value for your text color, like this:
Let me know if it doesn't work. It works for me.
我自己是 Android 的初学者,我不确定我在这里是否没有自取其辱,但是为什么不使用 android:textColor 属性呢?
I'm a beginner with Android myself and I'm not sure if I'm not making an ass of myself here, but why don't you use the android:textColor property?
我认为最好的方法是为不同的颜色和主题使用不同的布局 xml。根据用户选择加载布局 xml。我不喜欢这个,但我还没有找到任何替代方案。
I think best way is to have different layout xml for different colors and themes. Load the layout xml based on user choice. I do not like this but I have not found any alternatives.