Android删除操作栏

Sim*_*mon 7 android android-actionbar android-styles

我试图禁用我的一些活动的操作栏,但无论我尝试什么,我似乎无法删除它.

在我的styles.xml中,我有:

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

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

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)

在我的manifest.xml中,我有:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".NewActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

我的活动布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_new"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

我的app_bar_new布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="net.binarysea.sensorload.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_new" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我希望操作栏显示除一个(NewActivity)之外的活动.我使用Intent来调用NewActivity,此时我认为它会加载AppTheme.NoActionBar样式,但是栏仍然出现在屏幕上

我正在使用android studio中的导航抽屉活动,如果这有所不同

编辑:我已经尝试了所有建议添加添加Theme.AppCompat.Light.NoActionBar,但这只会使我的操作栏白色,并没有实际删除它.我在一个新的android工作室项目中测试了这个,创建了一个导航抽屉活动,并将主题设置添加到我的styles.xml中.我仍然遇到同样的问题

Sil*_*uti 8

试试这个...

只需为您的样式添加标记即可.

Styles.xml

 <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="windowActionBar">false</item>
   <item name="windowNoTitle">true</item>
 </style>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

 .......

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

     <activity
        android:name=".NewActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
      </activity>
   </application>
    ........
Run Code Online (Sandbox Code Playgroud)

  • 添加`Theme.AppCompat.Light.NoActionBar`只会使操作栏变白,而不会将其删除.请看我的编辑 (2认同)

Scr*_*tty 3

尝试将以下内容放入您的清单中 android:theme="@style/Theme.AppCompat.Light.NoActionBar"

  • 添加 `Theme.AppCompat.Light.NoActionBar` 只会使操作栏变白,而不会将其删除。请查看我的编辑 (2认同)