Android,如何在我的首选项中添加工具栏?

Android,如何在我的首选项中添加工具栏?,android,android-preferences,android-jetpack,android-jetpack-navigation,Android,Android Preferences,Android Jetpack,Android Jetpack Navigation,首先,我使用的是Jetpack导航组件-导航抽屉 “无操作栏”是我的应用程序的主要风格 假的 真的 @样式/前置时间 这是舱单 我的设置UI扩展了“PreferenceFragmentCompat”,它也在“nav_graph.xml”中定义 因此,可通过以下代码访问: findNavController().navigate(R.id.settingsFragment) 因为我的应用程序使用“NoActionBar”,所以首选项也没有操作栏。 而且首选项是由Jetpack首选

首先,我使用的是Jetpack导航组件-导航抽屉

“无操作栏”是我的应用程序的主要风格


假的
真的
@样式/前置时间
这是舱单


我的设置UI扩展了“PreferenceFragmentCompat”,它也在“nav_graph.xml”中定义

因此,可通过以下代码访问:

    findNavController().navigate(R.id.settingsFragment)
因为我的应用程序使用“NoActionBar”,所以首选项也没有操作栏。 而且首选项是由Jetpack首选项设置的,我无法添加自定义工具栏


请问有什么好主意/解决方案吗?

有很多解决方案。创建另一个样式,使actionbar成为true

<style name="AppTheme.WithActionBar" parent="AppTheme">
    <item name="windowActionBar">true</item>
    <item name="windowNoTitle">false</item>
    <item name="preferenceTheme">@style/PrefsTheme</item>
</style>

真的
假的
@样式/前置时间
然后,只在清单中的所需活动中应用该主题

<activity
        android:name="YourActivity"
        android:theme="@style/AppTheme.WithActionBar" />

我正在使用jetpack导航抽屉,
主活动
没有
操作栏
,而且我对
操作栏
有偏好,只是我在使用
应用主题

<activity
        android:name="YourPreferenceActivity"
        android:theme="@style/AppTheme" />
下面是我的AppTheme的外观

<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
AppTheme.NoActionBar

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

假的
真的

我的首选项在同一活动中。。。根据你的意见,我应该把我的偏好转移到另一个导航图上。但这看起来不是我想要的解决方案。@yoonhok请添加一些活动代码,以及如何在清单中定义活动,以便更好地理解问题。我添加了完整的清单代码。它只有一个活动,因为我使用Jetpack导航组件。是的,我使用带有导航抽屉的Jetpack导航组件。但是我的偏好在nav_图中,所以我认为您没有使用活动来保存偏好的片段
<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>