安卓隐藏导航栏

此方案在频幕有交互操作时状态栏和导航栏还会出来


private static Handler sHandler;  

 
protected void onCreate(Bundle savedInstanceState){    
    super.onCreate(savedInstanceState);     
 
    sHandler = new Handler();  
      
    sHandler.post(mHideRunnable); // hide the navigation bar  
 
    final View decorView = getWindow().getDecorView();  
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()  
        {  
            @Override  
            public void onSystemUiVisibilityChange(int visibility)  
            {  
                sHandler.post(mHideRunnable); // hide the navigation bar  
            }  
        });          
}  
 
Runnable mHideRunnable = new Runnable() {  
    @Override  
    public void run() {  
        int flags;    
        int curApiVersion = android.os.Build.VERSION.SDK_INT;  
        // This work only for android 4.4+  
        if(curApiVersion >= Build.VERSION_CODES.KITKAT){  
            // This work only for android 4.4+  
            // hide navigation bar permanently in android activity  
            // touch the screen, the navigation bar will not show  
            flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION  
                  | View.SYSTEM_UI_FLAG_IMMERSIVE  
                  | View.SYSTEM_UI_FLAG_FULLSCREEN;  
                  
        }else{  
            // touch the screen, the navigation bar will show  
            flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;  
        }  
          
        // must be executed in main thread :)  
        getWindow().getDecorView().setSystemUiVisibility(flags);  
    }  
}; 

你可能感兴趣的:(安卓隐藏导航栏)