Android remove action bar
Asked Answered
P

6

9

I'm trying to disable the action bar for some of my activities, but no matter what I try I can't seem to remove it.

In my styles.xml I have:

<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" />

And in my manifest.xml I have:

    <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>

My activity layout file:

<?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>

My app_bar_new layout file:

<?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>

I want the action bar to display on activities apart from one (NewActivity). I use intents to call up NewActivity, at which point I thought it would load up the AppTheme.NoActionBar style, but the bar still appears on the screen

I'm using the navigation drawer activity in android studio if that makes a difference

EDIT: I've tried all the suggesting adding Adding Theme.AppCompat.Light.NoActionBar, but that only makes my action bar white and doesn't actually remove it. I tested this in a new android studio project, created a navigation drawer activity, and add the theme setting to my styles.xml. I still get the same problem

Phyllous answered 25/2, 2016 at 2:54 Comment(4)
android:theme="@style/Theme.AppCompat.Light.NoActionBar" gets rid of it on my app. Put it in the appropriate activityHangup
post your avtivity_layout.xmlBickel
Do you expect like this..s1285.photobucket.com/user/imagamechanger_silambarasan/media/…Bickel
I have added my layout files. And yes, that is what I want (apart from the hamburger and settings icons)Phyllous
B
12

Try this...

Just add parent tag for your style.

Styles.xml

 <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="windowActionBar">false</item>
   <item name="windowNoTitle">true</item>
 </style>

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>
    ........
Bickel answered 25/2, 2016 at 3:38 Comment(1)
Adding Theme.AppCompat.Light.NoActionBar only makes the actionbar white, it doesn't remove it. Please see my editPhyllous
H
3

Try and drop the following into your manifest android:theme="@style/Theme.AppCompat.Light.NoActionBar"

Hangup answered 25/2, 2016 at 3:19 Comment(1)
Adding Theme.AppCompat.Light.NoActionBar only makes the actionbar white, it doesn't remove it. Please see my editPhyllous
D
3

MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
    getSupportActionBar().hide(); // hide the title bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
    setContentView(R.layout.activity_main);
}}
Dwt answered 12/8, 2021 at 9:58 Comment(0)
S
2

Follow this Link- https://developer.android.com/training/system-ui/status

Hide the Status Bar on Android 4.1 and Higher-Kotlin

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
supportActionBar?.hide()

Better use it inside onResume().

Another Solution https://mcmap.net/q/64754/-full-screen-theme-for-appcompat

Siegler answered 21/4, 2021 at 11:28 Comment(0)
T
0

Use like this in styles.xml

<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->

</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/drawer_bg</item>

</style>

Create seperate layout for toolbar

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

</android.support.v7.widget.Toolbar>

In any activity, access this toolbar by using below code.

Toolbar toolbar; //declaration

In onCreate() after setContentView() use this

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Translucent answered 25/2, 2016 at 3:22 Comment(3)
the manifest file and styles file you used will remove the action bar, to replace action bar with tool bar, use my code. It will add the toolbar in your activityTranslucent
Adding Theme.AppCompat.Light.NoActionBar only makes the actionbar white, it doesn't remove it. Please see my editPhyllous
set windowNoTitle to false in stylesTranslucent
I
0

You can try this in your onCreate() of NewActivity to hide the action bar for particular Activity

ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Illimitable answered 28/4, 2018 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.