I'm trying to remove/disable the ActionBar. I tried to put in the Manifest:
<activity
...
android:theme="@android:style/Theme.NoTitleBar"
</activity>
and it doesn't work. It doesn't remove the ActionBar. Please help me. Thanks.
I'm trying to remove/disable the ActionBar. I tried to put in the Manifest:
<activity
...
android:theme="@android:style/Theme.NoTitleBar"
</activity>
and it doesn't work. It doesn't remove the ActionBar. Please help me. Thanks.
I had this issue too. I went to styles.xml
and changed
parent="Theme.AppCompat.Light.DarkActionBar"
to
parent="Theme.AppCompat.Light.NoActionBar"
and that removed it from all my activities.
in your oncreate()
method use this
getActionBar().hide();
If your minSdkVersion
is 10 or lower, instead use:
getSupportActionBar().hide();
You can try this. It works for me
Add it in style.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
and use the style at manifest.xml.
android:theme="@style/AppTheme.NoActionBar"
For android studio You can go to styles.xml and change
parent="Theme.AppCompat.Light.DarkActionBar"
to
parent="Theme.AppCompat.Light.NoActionBar"
and in Eclipse it can be changed in manifest file
<activity
android:name="com.ExcellenceTech.webview.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
You hide action bar by with different ways.
1.action bar hidden through the manifest xml file (non Java Programming), then the easy way is to add the following attribute in Activity tag:
android:theme="@style/Theme.NoActionBar"
If custom Theme is created then it is convenient to create another style extending the custom theme.
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
or
ActionBar actionBar = getActionBar(); OR getSupportActionBar();
actionBar.hide();
getSupportActionBar().hide();
or
getActionBar().hide();
In AndroidManifest.xml and acitivity section put this code.
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
getActionBar().hide();
or
getSupportActionBar().hide();
But the change might not appear in the xml design.
Hide Action Bar permanently from styles.xml If you want to hide Action Bar throughout the app (Activities, Fragments) everywhere, you can simply navigate to res > values > styles.xml and change your Base application theme as mentioned below.
<resources>
<! - Base application theme. →
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<! - Customize your theme here. →
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Hide Action Bar for a particular activity:
Use this in onCreate(); Method
Kotlin:
supportActionBar?.hide()
Java:
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
I've found the easiest way by far, if you go to your AndroidManifest.xml file, you'll see android:theme="@style/Theme.yourappnamehere"
, you can simply replace that with android:theme="@style/Theme.AppCompat.Light.NoActionBar"
. Tada worked like a dream (no need to add anything)
you can use hideUi()
function as below and call it in onCreate()
method:
private void hideUI() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
View mContentView = (findViewById(R.id.mainLayout));
// Delayed removal of status and navigation bar
if (Build.VERSION.SDK_INT >= 30) {
mContentView.getWindowInsetsController().hide(
WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
} else {
// Note that some of these constants are new as of API 16 (Jelly Bean)
// and API 19 (KitKat). It is safe to use them, as they are inlined
// at compile-time and do nothing on earlier devices.
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
call the hideUI()
in onCrete()
after setContentView()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
hideUI();
// ......
}
I used the following codes and work for me:
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);