Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show title bar from code

In the manifest file I have this line to my application tag

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

and basically every activity doesn't have a title bar, but for one of the activities I want to show the title bar

I know that to hide the bar I can use this code

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

How can I show title bar from code ?

EDIT PLEASE do not tall me how can I hide the title bar :), I know that, if anybody know how can I show it ?

I know that I can put NoTitleBar in every activity that I want to hide and I can leave it for the one I want to be shown... But that was not my point

like image 222
Lukap Avatar asked Apr 29 '13 15:04

Lukap


3 Answers

For me thous lines of code work perfectly:

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);
like image 136
Eugine Avatar answered Oct 21 '22 03:10

Eugine


use

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

in each activity except the activity where you want to show the title. Dont use this theme in application attribute

according to your comment you want to make my change to only one place and it seems you dont want to make the chage in only one manifest(!). anywayy you can do another thing

use a BaseActivity Class where use the no title feature and extend it in all classes except the titled activity.

like image 3
stinepike Avatar answered Oct 21 '22 01:10

stinepike


Best way to do this is to reference this Try to use Window.FEATURE_CUSTOM_TITLE

Apparently this doesn't work and any other way seems to always crash

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

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

like image 1
JPM Avatar answered Oct 21 '22 01:10

JPM