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?
This question is related to
java
android
android-actionbar
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);
}
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" ... >
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>
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!
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"
/>
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.. :)
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!!!
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 -->
}
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">
There are multiple ways of doing this.
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.
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" ... />
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()
.
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"
If you're using AppCompat
, declare your activity in AndroidManifest.xml
as follows:
<activity
android:name=".SomeActivity"
...
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
Source: Stackoverflow.com