Android: how to hide ActionBar on certain activities
Apply the following in your Theme for the Activity in AndroidManifest.xml
:
<activity android:name=".Activity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How to hide Action Bar in Android Studio 4.1?
It doesn't depend by Android Studio.
Since you are using a AppCompatActivity
and you have to use getSupportActionBar()
instead of getActionBar()
.
As alternative you can use a .NoActionBar
theme, for example.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
</style>
How to hide ActionBar in android?
Your question isn't very clear and you should consider editing it, although,
I guess what you need is to change the theme
of your activity
in the AndroidManifest.xml
, i.e.:
<activity android:theme="@android:style/Theme.Holo.Light.NoActionBar">
Android Activity without ActionBar
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.
How to hide action bar buttons in certain activity?
When you switch between Activities every time you enter one it's onCreateOptionsMenu
is called. It is where you inflate your menu. If you want to not have action bar buttons in MainActivity then inflate empty menu in it. In SubActivity inflate menu with action bar buttons.
MainActivity.java
package com.example.user.twoactivities;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SubActivity.class));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
SubActivity.javva
package com.example.user.twoactivities;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class SubActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SubActivity.this, MainActivity.class));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.subactivity_menu, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button android:id="@+id/button"
android:text="Go to SubActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
activity_sub.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button android:id="@+id/button"
android:text="Go to MainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
menu_main.xml
<menu 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" tools:context=".MainActivity">
</menu>
subactivity_menu.xml
<menu 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" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings" android:icon="@drawable/ic_launcher"
android:orderInCategory="100" app:showAsAction="always" />
</menu>
Don't forget to add MainActivity and SubActivity to Manifest file.
How to hide the actionbar in some activities
(From the comments I wrote)
First, make your classes extends ActionBarActivity
. Then call this method in the onCreate()
callback of the activies in which you want to hide the action bar:
private void hideActionBar() {
//Hide the action bar only if it exists
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
}
Related Topics
Divide Elements on Groups in Recyclerview or Grouping Recyclerview Items ,Say by Date
Android (Java) Simple Send and Receive with Server - Fast Setup Challenge
How to Crop a Bitmap for Imageview
What Is the Use of Memoryfile in Android
Language Detection with Data in Postgresql
Converting a Java Arraylist of Strings to a JavaScript Array
Environment Variables in Eclipse
Simple Date Format Returns Wrong Date Intermittently
Setting a Spinner Onclicklistener() in Android
How to Wait for All Tasks in an Threadpoolexecutor to Finish Without Shutting Down the Executor
No Resource Identifier Found for Attribute 'Layout_Behavior' in Package
Date Format Conversion Android