Show title bar from code
Asked Answered
C

4

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

Convent answered 29/4, 2013 at 15:17 Comment(3)
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);Gastro
@Gastro it will crush i guessLaconism
You ned to handle displaying and hiding title bar in the Activity itself instead of setting the theme for it in the manifestBrander
C
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);
Chinkiang answered 5/6, 2013 at 8:39 Comment(0)
L
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.

Laconism answered 29/4, 2013 at 15:29 Comment(0)
G
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.

Gastro answered 29/4, 2013 at 16:54 Comment(0)
P
0

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

Android: this.supportActionBar?.hide();

Pericarp answered 14/3, 2022 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.