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

2

6

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

Drape answered 15/3, 2013 at 16:43 Comment(0)
T
23

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);
    }
Thermography answered 15/3, 2013 at 17:49 Comment(2)
awesome mate !!!! cheers for your awesome answer !!! it should be the accepted answer !!Tigress
Thanks @Tigress .. answering becomes meaningful when i get this kind of inspiration :)Thermography
S
0

There are couple of ways of doing so:

First Approach:

FEATURE_CUSTOM_TITLE

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.foo_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar); 
or

youractivity.setTitle();

NOTE! you can include a simple TextView in side your layout custom_title_bar

Make you custom_title_bar layout as follows:

   <LinearLayout           
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
      <TextView
         android:id="@+id/titleTextView"
         style="@android:style/WindowTitle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="TextView"
      />
    </LinearLayout>

Second Approach:

Activity.setTitle

this.setTitle("My Title!");
Stibine answered 15/3, 2013 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.