Android应用中,一般需要隐藏底部导航栏和状态栏(status and navigation bar),不同版本的android手机会稍稍不一样,下面是隐藏导航栏和状态栏的方法:
Android4.0及以下版本状态栏:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隐藏状态栏 if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } setContentView(R.layout.activity_main); } ... }
Android4.1及其以上版本隐藏状态栏status bar的方法:
View decorView = getWindow().getDecorView(); // 隐藏状态栏 int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); //隐藏状态栏时也可以把ActionBar也隐藏掉 ActionBar actionBar = getActionBar(); actionBar.hide();
隐藏导航栏,一般情况下也会把状态栏一起隐藏,代码如下:
View decorView = getWindow().getDecorView(); // SYSTEM_UI_FLAG_FULLSCREEN只适合Android4.1以上版本 //正常情况下隐藏导航栏,也会把状态栏给隐藏掉 int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions);