Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Show Activity Title/status bar at the top after it is hidden

Currently in my FragmentActivity, I hide the status bar by, in the onCreate method, doing the following:

 requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

this works no problem.

But in full screen, say user clicks a button, I will want to swap in another fragment (remember we are in FragmentActivity), I mean replacing the currently fragment that is displayed in full screen.

but I want the titlebar/status to be shown.

Is this possible? If so, how can I do it programmatically

like image 343
XyzNullPointer Avatar asked Mar 15 '13 16:03

XyzNullPointer


People also ask

How do I stop status bar from hiding?

If you want to bring the Notification Bar back, open Fullscreen: The One Immersive Mode again and tap "Hide Nothing." You can also tap the option next to "Fullscreen" to hide your Notification Bar and your Navigation Bar.

How will you hide the title of an activity?

The requestWindowFeature(Window. FEATURE_NO_TITLE) method of Activity must be called to hide the title.


1 Answers

Here you can change your title bar dynamically using following two methods. I called them from my Activity. So to call from Fragment you need the Activity instance.

public void hideTitle() {
        try {
            ((View) findViewById(android.R.id.title).getParent())
                    .setVisibility(View.GONE);
        } catch (Exception e) {
        }
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }

    public void showTitle() {
        try {
            ((View) findViewById(android.R.id.title).getParent())
                    .setVisibility(View.VISIBLE);
        } catch (Exception e) {
        }
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
like image 83
stinepike Avatar answered Nov 09 '22 14:11

stinepike