嵌套的首选项屏幕失去主题

发布于 2024-08-30 22:13:37 字数 935 浏览 1 评论 0原文

我的应用程序有一个首选项屏幕,并且在清单中我使用以下方式为其指定了一个主题:

android:theme="@android:style/Theme.Light.WallpaperSettings"

但是,当我在其中嵌套另一个首选项屏幕时,例如:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/setting_title"
    android:key="...">

    <PreferenceCategory
    android:title="@string/title_themes"
    >

    <PreferenceScreen
    android:title="@string/title_themes_opt"
    >

        <ListPreference
    android:key="Setting_BG"
    android:title="@string/setting_bg"
    android:summary="@string/setting_bg_summary"
    android:entries="@array/bg_titles"
    android:defaultValue="0"
    android:entryValues="@array/bg_values" />
    </PreferenceScreen>

    </PreferenceCategory>

</PreferenceScreen>

嵌套的首选项屏幕会丢失父级的主题。如何防止这种情况发生?提前致谢。

I have a preference screen for my application and in the manifest I have given it a theme using:

android:theme="@android:style/Theme.Light.WallpaperSettings"

However when I nest another preference screen inside this one such as:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/setting_title"
    android:key="...">

    <PreferenceCategory
    android:title="@string/title_themes"
    >

    <PreferenceScreen
    android:title="@string/title_themes_opt"
    >

        <ListPreference
    android:key="Setting_BG"
    android:title="@string/setting_bg"
    android:summary="@string/setting_bg_summary"
    android:entries="@array/bg_titles"
    android:defaultValue="0"
    android:entryValues="@array/bg_values" />
    </PreferenceScreen>

    </PreferenceCategory>

</PreferenceScreen>

The nested preference screen loses the theme of the parent. How can this be prevented? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2024-09-06 22:13:37

这是 Android 中的一个错误,请参阅 错误报告

This is a bug in android see the Bug Report.

握住我的手 2024-09-06 22:13:37

刚刚遇到这个问题。

虽然错误报告中的建议是创建您自己的自定义样式并设置列表视图背景,但我们发现为每个首选项屏幕创建单独的活动更容易。这使我们能够毫无问题地为每个屏幕设置 Theme.Light。

这不是一个很好的解决办法,但它确实有效。

Just ran into this problem.

While the suggestion in the bug report is to create your own custom style and set the listview background, we found it easier to create a separate activity for each preference screen. This allowed us to set the Theme.Light to each screen with no issue.

Not a great fix, but it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文