Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity without ActionBar

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?

like image 979
Lutscha Avatar asked Sep 16 '14 08:09

Lutscha


People also ask

How can use no action bar in Android?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme.


2 Answers

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.

like image 79
JRsz Avatar answered Oct 07 '22 16:10

JRsz


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().

like image 23
Confuse Avatar answered Oct 07 '22 16:10

Confuse