Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the title bar for an Activity in XML with existing custom theme

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:style/Theme.NoTitleBar.

Using the NoTitleBar theme as a parent for my style would remove the title bar from all of my activities.

Can I set a no title style item somewhere?

like image 505
Janusz Avatar asked Apr 07 '10 08:04

Janusz


People also ask

Which of the following attribute is used to hide the title of an activity in the manifest XML file in Android?

To hide the Title Bar using the Android Manifest. xml file you need to set the Android theme to NoTitleBar like this: android:theme="@android:style/Theme.

Which theme can be used to make a no title and no action bar window?

or use android:theme="@android:style/Theme. Black. NoTitleBar" if you don't need a fullscreen Activity. Note: If you've used a 'default' view before, you probably should also change the parent class from AppCompatActivity to Activity .


2 Answers

You can modify your AndroidManifest.xml:

<activity android:name=".MainActivity"           android:label="@string/app_name"           android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> 

or use android:theme="@android:style/Theme.Black.NoTitleBar" if you don't need a fullscreen Activity.

Note: If you've used a 'default' view before, you probably should also change the parent class from AppCompatActivity to Activity.

like image 23
Redax Avatar answered Sep 28 '22 16:09

Redax


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.

like image 135
YaW Avatar answered Sep 28 '22 16:09

YaW