6

目前在我的 中FragmentActivity,我通过在onCreate方法中执行以下操作来隐藏状态栏:

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

这没问题。

但是在全屏时,假设用户点击一个按钮,我会想要换入另一个片段(记住我们在 中FragmentActivity),我的意思是替换当前全屏显示的片段。

但我希望显示标题栏/状态。

这可能吗?如果是这样,我该如何以编程方式进行

4

2 回答 2

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);
    }
于 2013-03-15T17:49:51.593 回答
0

有几种方法可以这样做:

第一种方法:

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();

笔记!TextView您可以在布局中包含一个简单的内容custom_title_bar

让你custom_title_bar布局如下:

   <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>

第二种方法:

活动.setTitle

this.setTitle("My Title!");
于 2013-03-15T17:08:48.497 回答