Android隐藏动作栏和工具栏

3

在清单文件中我使用了

minSdkVersion 14
targetSdkVersion 23

现在,我想隐藏主题:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ir.pishguy.simpleadvancepagedesign">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
    </style>

</resources>

但我遇到了这个错误:
    Caused by: java.lang.IllegalStateException: You need to use a 
Theme.AppCompat theme (or descendant) with this activity.
3个回答

2

在活动中使用 getSupportActionBar().hide();

或者在片段中使用 getActivity.getSupportActionBar().hide();


1

只需将这个:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">

替换为这个:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

如果你想在setSupportActionbar(Toolbar toolBar)方法后隐藏工具栏,请使用getSupportActionbar().hide();

希望对你有所帮助!!!


1

请查看我的解决方案,链接在这里

或者

使用样式

<style name="FullScreenTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- ... -->
</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接