Android:偏好风格
我制作了一个自定义首选项(即具有自定义布局的首选项),该首选项显示在 PreferenceActivity
的首选项列表中。
布局是用代码创建的。问题在于,在代码中创建的 TextView 的字体看起来与 Android 的标准偏好字体有些不同。
因此,解决方案是将 android 首选项的样式属性应用到我的 TextView
上。各自的样式应为 preferenceScreenStyle 或 preferenceStyle (我不确定)。
我的问题是我不知道如何读取android的标准样式属性,所以我可以在代码中设置它们。
I have made a custom preference (i.e. a preference with a custom layout) which displayed in the preferences list of a PreferenceActivity
.
The layout is created in code. The problem is that the font of the TextView created in code looks somewhat different than Android's standard preference font.
So the solution would be to apply the style attributes of android's preference to my TextView
. The respective styles should be preferenceScreenStyle or preferenceStyle (I'm not sure).
My problem is I can't figure out how to read out android's standard style attributes, so I could set them in code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题,但我已针对某些移动设备(HTC Saphire 和 Samsung Galaxy S)修复了该问题,但我的 HTC Desire HD 遇到了问题。您可以在 android_SDK_resurces/layout/preference.xml 中看到标准首选项样式。有边距,文字大小,......
I've the same problem but i fixed it out for some mobile devices,HTC Saphire and Samsung Galaxy S, but i'have problems with my HTC Desire HD. You can see standard preference style in android_SDK_resurces/layout/preference.xml. There are the margins, text sizes,....
为死灵道歉,但我无法在任何有关偏好样式的问题上找到答案。我终于找到了答案:默认首选项现在使用
layout/preference_material
。您可以在 android 源代码中查看它和其他更具体的布局Apologies for the necro but I was not able to find this answer on any SO question about preference styling. I finally found the answer: the default preference now uses the
layout/preference_material
. You can see it and other more specific layouts at the android source here. Copied below just in case that link breaks:我设法通过将当前自定义首选项的布局资源替换为标准首选项(如 EditTextPreference)使用的布局资源来解决此问题,例如,这是一个代码示例,请注意,TimePreference 是自定义首选项。
I've managed to solve this by replacing current custom preference's layout resource with layout resource used by a standard preference like EditTextPreference e.g. Here is a code example, note that TimePreference is the custom preference.