代码方式隐藏状态栏
Posted yongfengnice
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码方式隐藏状态栏相关的知识,希望对你有一定的参考价值。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Hide toolbar int SDK_INT = android.os.Build.VERSION.SDK_INT; if(SDK_INT >= 19) { setImmersiveSticky(); View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { setImmersiveSticky(); } }); } } @Override protected void onResume() { super.onResume(); //Hide toolbar int SDK_INT = android.os.Build.VERSION.SDK_INT; if(SDK_INT >= 11 && SDK_INT < 14) { getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN); } else if(SDK_INT >= 14 && SDK_INT < 19) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE); } else if(SDK_INT >= 19) { setImmersiveSticky(); } } void setImmersiveSticky() { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); }
以上是关于代码方式隐藏状态栏的主要内容,如果未能解决你的问题,请参考以下文章