Android 隐藏底部虚拟键的两种方法

作者:袖梨 2022-06-25

方法一  滑动屏幕 可重新显示出来

protected void hideBottomUIMenu() {
  //隐藏虚拟按键,并且全屏
  if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
    View v = this.getWindow().getDecorView();
    v.setSystemUiVisibility(View.GONE);
  } else if (Build.VERSION.SDK_INT >= 19) {
    //for new api versions.
    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);

  }
}

方法二  滑动也不能重新显示

protected void hideBottomUIMenu() {
  //隐藏虚拟按键,并且全屏
  if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
    View v = this.getWindow().getDecorView();
    v.setSystemUiVisibility(View.GONE);
  } else if (Build.VERSION.SDK_INT >= 19) {
    
    Window _window = getWindow();
    WindowManager.LayoutParams params = _window.getAttributes();
    params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE;
    _window.setAttributes(params);
  }
}

相关文章

精彩推荐