<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                > 編寫:[K0ST](https://github.com/K0ST) - 原文:[http://developer.android.com/training/system-ui/status.html](http://developer.android.com/training/system-ui/status.html) **這節課將教您** 1. 在4.0及以下版本中隱藏狀態欄 1. 在4.1及以上版本中隱藏狀態欄 1. 在4.4及以上版本中隱藏狀態欄 1. 讓內容顯示在狀態欄之后 1. 同步狀態欄與Action Bar的變化 **同時您應該閱讀** - [Action Bar API 指南](http://developer.android.com/guide/topics/ui/actionbar.html) - [Android Design Guide](http://developer.android.com/design/index.html) 本課程將教您如何在不同版本的Android下隱藏狀態欄。隱藏狀態欄(或者是導航欄)可以讓內容得到更多的展示空間,從而提供一個更加沉浸式的用戶體驗。 圖1展示了顯示狀態欄的界面 ![status_bar_show](https://box.kancloud.cn/2015-07-28_55b72478698c0.png) **圖1**. 顯示狀態欄. 圖2展示了隱藏狀態欄的界面。請注意,Action Bar這個時候也被隱藏了。請永遠不要在隱藏狀態欄的時候顯示Action Bar。 ![status_bar_hide](https://box.kancloud.cn/2015-07-28_55b724787a5ff.png) **圖2**. 隱藏狀態欄. ### 在4.0及以下版本中隱藏狀態欄 在Android 4.0及更低的版本中,你可以通過設置`WindowManager`來隱藏狀態欄。你可以動態的隱藏,也可以在你的manifest文件中設置[Activity](# "An activity represents a single screen with a user interface.")的主題。如果你的應用的狀態欄在運行過程中會一直隱藏,那么推薦你使用改寫manifest設定主題的方法(嚴格上來講,即便設置了manifest你也可以動態的改變界面主題)。 ~~~ <application ... android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" > ... </application> ~~~ 設置主題的優勢是: - 易于維護,且不像動態設置標簽那樣容易出錯 - 有更流暢的UI轉換,因為在初始化你的[Activity](# "An activity represents a single screen with a user interface.")之前,系統已經得到了需要渲染UI的信息 另一方面我們可以選擇使用`WindowManager`來動態隱藏狀態欄。這個方法可以更簡單的在用戶與App進行交互式展示與隱藏狀態欄。 ~~~ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If the Android version is lower than Jellybean, use this call to hide // the status bar. if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } setContentView(R.layout.activity_main); } ... } ~~~ 當你設置`WindowManager`標簽之后(無論是通過[Activity](# "An activity represents a single screen with a user interface.")主題還是動態設置),這個標簽都會一直生效直到你清除它。 設置了`FLAG_LAYOUT_IN_SCREEN`之后,你可以擁有與啟用`FLAG_FULLSCREEN`后相同的屏幕區域。這個方法防止了狀態欄隱藏和展示的時候內容區域的大小變化。 ### 在4.1及以上版本中隱藏狀態欄 在Android 4.1(API level 16)以及更高的版本中,你可以使用[setSystemUiVisibility()](http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int))來進行動態隱藏。`setSystemUiVisibility()`在View層面設置了UI的標簽,然后這些設置被整合到了Window層面。`setSystemUiVisibility()`給了你一個比設置`WindowManager`標簽更加粒度化的操作。下面這段代碼隱藏了狀態欄: ~~~ View decorView = getWindow().getDecorView(); // Hide the status bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should never show the action bar if the // status bar is hidden, so hide that too if necessary. ActionBar actionBar = getActionBar(); actionBar.hide(); ~~~ 注意以下幾點: - 一旦UI標簽被清除(比如跳轉到另一個[Activity](# "An activity represents a single screen with a user interface.")),如果你還想隱藏狀態欄你就必須再次設定它。詳細可以看第五節如何監聽并響應UI可見性的變化。 - 在不同的地方設置UI標簽是有所區別的。如果你在[Activity](# "An activity represents a single screen with a user interface.")的onCreate()方法中隱藏系統欄,當用戶按下home鍵系統欄就會重新顯示。當用戶再重新打開[Activity](# "An activity represents a single screen with a user interface.")的時候,onCreate()不會被調用,所以系統欄還會保持可見。如果你想讓在不同[Activity](# "An activity represents a single screen with a user interface.")之間切換時,系統UI保持不變,你需要在onResume()與onWindowFocusChaned()里設定UI標簽。 - setSystemUiVisibility()僅僅在被調用的View顯示的時候才會生效。 - 當從View導航到別的地方時,用setSystemUiVisibility()設置的標簽會被清除。 ### 讓內容顯示在狀態欄之后 在Android 4.1及以上版本,你可以將應用的內容顯示在狀態欄之后,這樣當狀態欄顯示與隱藏的時候,內容區域的大小就不會發生變化。要做到這個效果,我們需要用到`SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN`這個標志。同時,你也有可能需要`SYSTEM_UI_FLAG_LAYOUT_STABLE`這個標志來幫助你的應用維持一個穩定的布局。 當使用這種方法的時候,你就需要來確保應用中特定區域不會被系統欄掩蓋(比如地圖應用中一些自帶的操作區域)。如果被覆蓋了,應用可能就會無法使用。在大多數的情況下,你可以在布局文件中添加`android:fitsSystemWindows`標簽,設置它為true。它會調整父ViewGroup使它留出特定區域給系統欄,對于大多數應用這種方法就足夠了。 在一些情況下,你可能需要修改默認的padding大小來獲取合適的布局。為了控制內容區域的布局相對系統欄(它占據了一個叫做“內容嵌入”`content insets`的區域)的位置,你可以重寫`fitSystemWindows(Rect insets)`方法。當窗口的內容嵌入區域發生變化時,`fitSystemWindows()`方法會被view的hierarchy調用,讓View做出相應的調整適應。重寫這個方法你就可以按你的意愿處理嵌入區域與應用的布局。 ### 同步狀態欄與Action Bar的變化 在Android 4.1及以上的版本,為了防止在Action Bar隱藏和顯示的時候布局發生變化,你可以使用Action Bar的overlay模式。在Overlay模式中,[Activity](# "An activity represents a single screen with a user interface.")的布局占據了所有可能的空間,好像Action Bar不存在一樣,系統會在布局的上方繪制Aciton Bar。雖然這會遮蓋住上方的一些布局,但是當Action Bar顯示或者隱藏的時候,系統就不需要重新改變布局區域的大小,使之無縫的變化。 要啟用Action Bar的overlay模式,你需要創建一個繼承自Action Bar主題的自定義主題,將`android:windowActionBarOverlay`屬性設置為true。要了解詳細信息,請參考[添加Action Bar](#)課程中的[Action Bar的覆蓋層疊](#)。 設置`SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN`來讓你的[activity](# "An activity represents a single screen with a user interface.")使用的屏幕區域與設置`SYSTEM_UI_FLAG_FULLSCREEN`時的區域相同。當你需要隱藏系統UI時,使用`SYSTEM_UI_FLAG_FULLSCREEN`。這個操作也同時隱藏了Action Bar(因為`windowActionBarOverlay="true"`),當同時顯示與隱藏ActionBar與狀態欄的時候,使用一個動畫來讓他們相互協調。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看