I want to hide the titlebar for some of my activities. The problem is that I applied a style to all my activities, therefore I can\'t simply set the theme to @android:
I believe there is just one line answer for this in 2020
Add the following line to the styles.xml
<item name="windowNoTitle">true</item>
The title bar can be removed in two ways as mentioned on the developer Android page:
In the manifest.xml
file:
Add the following in application
if you want to remove it for all the activities in an app:
<application android:theme="@android:style/Theme.Black.NoTitleBar">
Or for a particular activity:
<activity android:theme="@android:style/Theme.Black.NoTitleBar">
If you use this.requestWindowFeature(Window.FEATURE_NO_TITLE)
user will still be able to see the title bar just for a moment during launch animation when activity starts through onCreate
. If you use @android:style/Theme.Black.NoTitleBar
as shown below then title bar won't be shown during launch animation.
<activity
android:name=".MainActivity"
android:label="My App"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:screenOrientation="portrait">
above example will obviously override your existing application theme, if you have existing theme then add <item name="android:windowNoTitle">true</item>
to it.
This is how the complete code looks like. Note the import of android.view.Window.
package com.hoshan.tarik.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
}
Do this in your onCreate()
method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
this
refers to the Activity
.
add in manifiest file ,
android:theme="@android:style/Theme.Translucent.NoTitleBar"
add following line into ur java file,
this.requestWindowFeature(Window.FEATURE_NO_TITLE);