天天看點

setSystemUiVisibility() 與 getSystemUiVisibility() 顯示隐藏狀态欄

/** 

 * If {@param visible} is false, this hides the action bar and switches the 

 * system UI to lights-out mode. If {@param hideLater} is true, a delayed message 

 * will be sent after a timeout to hide the action bar. 

 */  

private void setSystemBarsVisibility(boolean visible, boolean hideLater) {  

    mMainHandler.removeMessages(HIDE_ACTION_BAR);  

    int currentSystemUIVisibility = mAboveFilmstripControlLayout.getSystemUiVisibility();  

    int newSystemUIVisibility = DEFAULT_SYSTEM_UI_VISIBILITY |  

            (visible ? View.SYSTEM_UI_FLAG_VISIBLE :  

                    View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN);  

    if (newSystemUIVisibility != currentSystemUIVisibility) {  

        mAboveFilmstripControlLayout.setSystemUiVisibility(newSystemUIVisibility);  

    }  

    boolean currentActionBarVisibility = mActionBar.isShowing();  

    if (visible != currentActionBarVisibility) {  

        if (visible) {  

            mActionBar.show();  

        } else {  

            mActionBar.hide();  

        }  

        if (mOnActionBarVisibilityListener != null) {  

            mOnActionBarVisibilityListener.onActionBarVisibilityChanged(visible);  

    // Now delay hiding the bars  

    if (visible && hideLater) {  

        mMainHandler.sendEmptyMessageDelayed(HIDE_ACTION_BAR, SHOW_ACTION_BAR_TIMEOUT_MS);  

}  

這個方法主要封裝的就是是否顯示狀态欄與 ActionBar.

View類提供了setSystemUiVisibility和getSystemUiVisibility方法,這兩個方法實作對狀态欄的動态顯示或隐藏的操作,以及擷取狀态欄目前可見性。

   setSystemUiVisibility(int visibility)方法可傳入的實參為:

    1. View.SYSTEM_UI_FLAG_VISIBLE:顯示狀态欄,Activity不全屏顯示(恢複到有狀态的正常情況)。

    2. View.INVISIBLE:隐藏狀态欄,同時Activity會伸展全屏顯示。

    3. View.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏顯示,且狀态欄被隐藏覆寫掉。

    4. View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏顯示,但狀态欄不會被隐藏覆寫,狀态欄依然可見,Activity頂端布局部分會被狀态遮住。

    5. View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

    6. View.SYSTEM_UI_LAYOUT_FLAGS:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

    7. View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隐藏虛拟按鍵(導航欄)。有些手機會用虛拟按鍵來代替實體按鍵。

    8. View.SYSTEM_UI_FLAG_LOW_PROFILE:狀态欄顯示處于低能顯示狀态(low profile模式),狀态欄上一些圖示顯示會被隐藏。

    本文轉自 一點點征服   部落格園部落格,原文連結:http://www.cnblogs.com/ldq2016/p/7110764.html,如需轉載請自行聯系原作者