隐藏底部虚拟键盘后会吸掉点击事件,出现点击2次

Android在隐藏底部虚拟按键的时候Google官方答案

https://developer.android.com/training/system-ui/navigation.html#behind

代码示例:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

| View.SYSTEM_UI_FLAG_FULLSCREEN;

decorView.setSystemUiVisibility(uiOptions);

但是这样会出现一个问题,就是在界面上如果有按钮那么点击这个按钮要点击2次才能触发点击事件!

最终解决应该是

//隐藏虚拟按键,并且全屏

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);

}

你可能感兴趣的:(隐藏底部虚拟键盘后会吸掉点击事件,出现点击2次)