2013-03-15 31 views
6

目前在我FragmentActivity,我隱藏的狀態欄,在onCreate方法,執行以下操作:Android的展會活動名稱在頂部/狀態欄後,它隱藏

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

這工作沒有任何問題。如果用戶點擊一個按鈕,我想在另一個片段中切換(記住我們在FragmentActivity),我的意思是替換當前全屏顯示的片段。

但我想標題欄/狀態顯示。

這可能嗎?如果是這樣,我怎麼能做到這一點編程

回答

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> 

方法二:

Activity.setTitle

this.setTitle("My Title!"); 
22

在這裏,您可以改變你的標題欄動態使用以下兩種方法。我從我的Activity打電話給他們。因此,要撥打Fragment,您需要使用Activity實例。

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); 
    } 
+1

這工作完美,應該是被接受的答案。 – 2013-09-30 14:43:19

+0

@MarkBuikema你應該有upvoted然後:p – stinepike 2013-10-01 06:07:06

+1

真棒隊友!歡呼你的真棒答案!它應該是被接受的答案! – Rudi 2013-10-28 08:37:17