首先,我正在使用Jetpack导航组件-导航抽屉。
并且“ No Action Bar”是我应用程序的主要样式。
<style name="NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">@style/PrefsTheme</item>
</style>
这里是清单。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".MainApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
因为我使用了Jetpack导航组件,所以它是单个活动模式。
[通常,我的UI具有自定义工具栏。可以。
但是在设置UI的情况下,我遇到了问题...
我正在使用Jetpack首选项。 https://developer.android.com/guide/topics/ui/settigs
我的设置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导航抽屉,但MainActivity
没有Actionbar
,我也具有Actionbar
的首选项,只是我正在使用AppTheme
<activity
android:name="YourPreferenceActivity"
android:theme="@style/AppTheme" />
注意:如果您使用默认设置,则可以在
PreferenceActivity
中删除主题主题是AppTheme
没有动作栏主题的MainActivity
<activity
android:name="com.jca.dastuurkajsl.ui.main.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是我的[[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>