7

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

Lukap
  • 31,523
  • 64
  • 157
  • 244
  • This is a good question! I don't see anything that will let you stuff it back in once removed. Maybe use the requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); – JPM Apr 29 '13 at 15:23
  • @JPM it will crush i guess – stinepike Apr 29 '13 at 15:24
  • You ned to handle displaying and hiding title bar in the Activity itself instead of setting the `theme` for it in the manifest – Pragnani Apr 29 '13 at 15:25

4 Answers4

6

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);
Eugine
  • 61
  • 2
3

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.

stinepike
  • 54,068
  • 14
  • 92
  • 112
1

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.

Community
  • 1
  • 1
JPM
  • 9,077
  • 13
  • 78
  • 137
0

Just add below line to hide in your activity's OnCreate method Java: this.getSupportActionBar().hide();

Android: this.supportActionBar?.hide();