Android Activity without ActionBar

JavaAndroidAndroid Actionbar

Java Problem Overview


I have different Activities in my App and in all of them I do not want the Action Bar. I cannot find how to disable it. I have tried to find an attribute to apply it to the main_activity.xml but so far I did not find anything. Can somebody help me please?

Java Solutions


Solution 1 - Java

Haha, I have been stuck at that point a while ago as well, so I am glad I can help you out with a solution, that worked for me at least :)

What you want to do is define a new style within values/styles.xml so it looks like this

<resources>
    <style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
    </style>

</resources>

Only the NoActionBar style is intresting for you. At last you have to set is as your application's theme in the AndroidManifest.xml so it looks like this

<application
    android:allowBackup = "true"
    android:icon = "@drawable/ic_launcher"
    android:label = "@string/app_name"
    android:theme = "@style/NoActionBar"   <!--This is the important line-->
    >
    <activity
	[...]
	

I hope this helps, if not, let me know.

Solution 2 - Java

There are multiple ways of doing this.

1) Change the theme in Android Manifest

Below the Application element, you will find theme tag. Replace it with this one -

android:theme="@android:style/Theme.NoTitleBar"

If you are using AppCompat, use @android:style/Theme.AppCompat.NoActionBar.

This will set the theme for all activities. If you don't need the action bar in a specific acitivity, then set the theme in the activity container, ie

<activity android:theme="@android:style/Theme.NoTitleBar" ...>

You may also set android:theme="@android:style/Theme.NoTitleBar" theme in the styles and use it later on.


2) Create a Custom Theme

Add this in res/values/styles.xml

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
     <item name="windowActionBar">false</item>
     <item name="android:windowNoTitle">true</item>
</style>

and then set it as your activity's theme in Manifest:

<activity android:theme="@style/NoActionBar" ... />

3) Dynamically Remove the Action Bar

Put this code in the onCreate method before setting content view -

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();

If you are using the support library use getSupportActionBar().

Solution 3 - Java

If you're using AppCompat, declare your activity in AndroidManifest.xml as follows:

<activity
    android:name=".SomeActivity"
    ...
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

Solution 4 - Java

Considering everyone is posting older ways of hiding the ActionBar here is the proper way of implementing it within styles for AppCompat support library. Which I highly suggest moving toward if you haven't already.

Simply removing the ActionBar

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

If you are using the appcompat support libraries, this is the easiest and recommended way of hiding the ActionBar to make full screen or start implementing to toolbar within your layouts.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Your Toolbar Color-->
    <item name="colorPrimary">@color/primary</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/primary_dark</item>

    <!-- colorAccent is used as the default value for colorControlActivated,
     which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>

    <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight, and colorSwitchThumbNormal. -->
</style>

Then to change your toolbar color

<android.support.v7.widget.Toolbar
	android:id=”@+id/my_awesome_toolbar”
	android:layout_height=”wrap_content”
	android:layout_width=”match_parent”
	android:minHeight=”?attr/actionBarSize”
	android:background=”?attr/primary” />

Last note: Your Activity class should extend AppCompatActivity

public class MainActivity extends AppCompatActivity {

<!--Activity Items -->

}

Solution 5 - Java

Default style you getting in res/value/style.xml like

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

And just the below like in your activity tag,

android:theme="@style/AppTheme.NoActionBar"

Solution 6 - Java

If you want most of your activities to have an action bar you would probably inherit your base theme from the default one (this is automatically generated by Android Studio per default):

<!-- Base application theme. -->
    <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>

And then add a special theme for your bar-less activity:

<style name="AppTheme.NoTitle" parent="AppTheme">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="actionBarTheme">@null</item>
    </style>

For me, setting actionBarTheme to @null was the solution.

Finally setup the activity in your manifest file:

<activity ... android:theme="@style/AppTheme.NoTitle" ... >

Solution 7 - Java

You may also change inheritance from ActionBarActivity to Activity as written here.

UPDATE

A good solution is here:

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_main);
}

Solution 8 - Java

open Manifest and add attribute theme = "@style/Theme.AppCompat.Light.NoActionBar" to activity you want it without actionbar :

<application
    ...
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        ...
    </activity>
</application>

Solution 9 - Java

I will try to show it as simple as i can:

DECLARE FULL SCREEN ACTIVITY IN ANDROID MAINIFEST file:

<activity
            android:name=".GameActivity"
            android:label="@string/title_activity_game"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

Now in Android studio (if you using it) open your Activity xml file ( in my example activity_game.xml) in designer and select theme (above mobile phone in designer click button with small circle) and then select Mainfest Themes on the left side and then NoTitleBar.Fullscreen.

Hope it will help!

Solution 10 - Java

Please find the default theme in styles.xml

<!-- Base application theme. -->
    <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>

And change parent this way

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

Solution 11 - Java

android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"

Using this theme worked for me

Solution 12 - Java

Put this line in your Activity in the Manifest:

<activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        ...
    </activity>

and make sure you didn't put Toolbar in your layout

 <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            />

Solution 13 - Java

Create an new Style with any name, in my case "Theme.Alert.NoActionBar"

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

set its parent as "Theme.AppCompat.Dialog" like in the above code

open AndoridManifest.xml and customize the activity you want to show as Alert Dialog like this

    <activity
        android:excludeFromRecents="true"
        android:theme="@style/Theme.Alert.NoActionBar"
        android:name=".activities.UserLoginActivity" />

in my app i want show my user login activity as Alert Dialog, these are the codes i used. hope this works for you!!!

Solution 14 - Java

It's Really Simple Just go to your styles.xml change the parent Theme to either Theme.AppCompat.Light.NoActionBar or Theme.AppCompat.NoActionbar and you are done.. :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLutschaView Question on Stackoverflow
Solution 1 - JavaJRszView Answer on Stackoverflow
Solution 2 - JavaConfuseView Answer on Stackoverflow
Solution 3 - JavaatablashView Answer on Stackoverflow
Solution 4 - JavaEugene HView Answer on Stackoverflow
Solution 5 - JavaPrashant MhetreView Answer on Stackoverflow
Solution 6 - JavaClaudeView Answer on Stackoverflow
Solution 7 - JavaCoolMindView Answer on Stackoverflow
Solution 8 - JavaMahmoud Salah EldinView Answer on Stackoverflow
Solution 9 - Javauser4009281View Answer on Stackoverflow
Solution 10 - JavaD. SergeevView Answer on Stackoverflow
Solution 11 - JavaZohab AliView Answer on Stackoverflow
Solution 12 - JavaMohamed Ben RomdhaneView Answer on Stackoverflow
Solution 13 - JavaKarthickView Answer on Stackoverflow
Solution 14 - Javamustansir makdaView Answer on Stackoverflow