Android偏好标题/摘要文本样式
我有几个自定义首选项 - 一个显示当前所选颜色的样本,另一个显示缩略图。
我有一个匹配得很好的自定义布局,并且发现我可以通过使用 android:textAppearance="?android:attr/textAppearanceLarge" 作为 TextView xml 的一部分来使文本外观匹配。问题是,虽然这些通常看起来不错,但它们一定不是“官方”偏好使用的外观,因为颜色最终在某些设备上出现错误。特别是,我将我的应用程序移植到 Nook Color,它在首选项屏幕上使用浅灰色背景和黑色文本颜色,而不是黑色背景/浅灰色文本。在这种情况下,我的文本颜色保持不变,但布局的其余部分主题适当。
我真的不确定我应该在这里做什么以使我的文本与“官方”主题相匹配。我应该使用 getStyledAttributes 并运行我的布局来设置内容吗?到目前为止,我所看到的使用它的教程确实令人困惑,而且似乎必须有一个我可以在 XML 中设置的 textAppearance 或样式来解决这个问题。
I have a couple custom preference items -- one that displays a swatch of the currently selected color, and another one that displays a thumbnail.
I have a custom layout for these that matches up very well, and have found that I can make the text appearance match by using android:textAppearance="?android:attr/textAppearanceLarge" as part of the TextView's xml. The problem is, while these generally look fine, they must not be the appearance the 'official' preferences use, since the colors end up wrong on some devices. In particular I'm porting my application to the Nook Color, and it uses a light grey background and black text color on the preference screen instead of black background/light grey text. My text color in this situation stays the same, but the rest of my layout is themed appropriately.
I'm really unsure what I'm supposed to do here to make my text match up with the 'official' theme. Should I be using obtainStyledAttributes and running though my layout to set things? The tutorials I've seen on using that so far have been really baffling, and it seems like there must be a textAppearance or style I can set in the XML to fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须定义自己的应用程序主题,该主题继承自您想要的官方主题。实际上,您可以定义一个扩展
Theme.Light
的主题MyTheme
。创建一个像这样的
res/values/styles.xml
文件:然后,您只需使用
application
android:theme 属性来应用您的主题AndroidManifest.xml
的 code> 实体:You've to define your own application theme which inherits from the official theme you want. Actually, you can just define a theme
MyTheme
extending theTheme.Light
for example.Create an
res/values/styles.xml
file like that:Then, you just have to apply your theme using the
android:theme
attribute of theapplication
entity of yourAndroidManifest.xml
: