如何为活动应用光主题并同时保持对话框的黑暗主题?(How to apply light theme for the activity and keep the dark theme for the d

编程入门 行业动态 更新时间:2024-10-08 08:25:23
如何为活动应用光主题并同时保持对话框的黑暗主题?(How to apply light theme for the activity and keep the dark theme for the dialogs at the same time?)

有没有办法可以为PreferenceActivity应用自定义样式,它将从Theme.Sherlock.Light或Theme.Light继承并保留preferenceDialog和AlertDialogs的黑暗样式? 我可以轻松地将对话框排除在应用光样式之外吗? 如果没有我应该设置哪些属性,在浅色主题中分隔符,文本活动,非活动,标题和副标题等中使用的默认颜色的参数是什么? 谢谢。

Is there a way that I could apply a custom style for an PreferenceActivity, which will inherit from Theme.Sherlock.Light or Theme.Light and keep the dark style for the preferenceDialog and AlertDialogs? Can I easily exclude dialogs from applying light style? if no which attributes should I set and what are the parameters of the default colors used in dividers, text active, inactive, titles and subtitles etc. in light theme? Thanks.

最满意答案

我通过将活动主题更改为光来解决它,然后我以编程方式将警报对话框的主题设置为黑暗的,内置的android样式之一:

this.setTheme(android.R.style.Theme_Holo_Dialog);

由于PreferenceDialog继承自Dialog,因此它也将此主题设置为所有PreferenceDialogs。 为了更具体,并为特定对话框添加样式,您可以使用在android源代码中的Dialog.java中使用的ContextThemeWrapper:

builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault_Dialog))

I solved it by changing the activity theme to light and then I set programmatically the theme of the alert dialog to the one of the dark, built in android styles:

this.setTheme(android.R.style.Theme_Holo_Dialog);

Since PreferenceDialog inherits from Dialog it also set this theme to all PreferenceDialogs. To be more specific and add a style to a particular dialog you can use ContextThemeWrapper as used in Dialog.java in android source:

builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault_Dialog))

更多推荐

style,样式,light,电脑培训,计算机培训,IT培训"/> <meta name="description&qu

本文发布于:2023-07-09 10:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主题   用光   对话框   何为   黑暗

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!