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:
You can use this code in your java file
add this line before you set or load your view
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
what works for me:
1- in styles.xml:
<style name="generalnotitle" parent="Theme.AppCompat.Light" >
<item name="android:windowNoTitle">true</item> <!-- //this -->
</style>
2- in MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //<< this
setContentView(R.layout.activity_main);
}
in manifest inherit the style:
<activity android:name=".MainActivity" android:theme="@style/generalnotitle">
Add both of those for the theme you use:
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
To Hide both Title and Action bar I did this:
In activity tag of Manifest:
android:theme="@style/AppTheme.NoActionBar"
In Activity.java before setContentView:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
i.e.,
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
NOTE: You need to keep these lines before setContentView
Add theme @style/Theme.AppCompat.Light.NoActionBar in your activity on AndroidManifest.xml like this
<activity
android:name=".activities.MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
If you do what users YaW and Doug Paul say, then you have to have in mind that window features must be set prior to calling setContentView. If not, you will get an exception.