Show title bar from code

In the manifest file, I use this line for my application tag

android:theme="@android:style/Theme.NoTitleBar" 

and basically each action does not have a title bar, but for one of the actions I want to show a title bar

I know that to hide the panel, I can use this code

 this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

How to show title bar from code?

EDIT PLEASE do not raise me, how can I hide the title :) I know this if anyone knows how I can show it?

I know that I can put NoTitleBar in every action that I want to hide, and I can leave it for the one I want to show ... But this is not my point.

+7
source share
3 answers

For me, thousands of lines of code work just fine:

Hide

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 

Show:

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
+5
source

use

  android:theme="@android:style/Theme.NoTitleBar" 

in every action except the action in which you want to show the title. Do not use this theme in the application attribute

according to your comment, you want to make my change in only one place, and it seems that you do not want to chage in only one manifest (!). in any case, you can do another thing

use the BaseActivity class, where you use an untitled function and extend it in all classes except for title activity.

+3
source

The best way to do this is to reference this. Try using Window.FEATURE_CUSTOM_TITLE

This doesn't seem to work, and any other way always fails

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.settings); activity.setTitle("Settings"); 

I am sure this is the way to do this with code.

+1
source

All Articles