Android 解决隐藏了导航栏(虚拟按键)后弹出PopupWindow 后又显示导航栏的问题


更新

又出现导航栏的原因是设置了

pWindow.setFocusable(false);










隐藏导航栏的方法


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

    }
}
此方法在activity的
setContentView();
前调用


在PopupWindow 中再次调用一次就可以隐藏了


contentView = inflater.inflate(R.layout.popup_stop, null);
pWindow = new android.widget.PopupWindow(-2, -2);
pWindow.setContentView(contentView);
backgroundAlpha(0.5f);
pWindow.setAnimationStyle(R.style.popupwin_style);
pWindow.setFocusable(false);
pWindow.setOutsideTouchable(false);
pWindow.setInputMethodMode(android.widget.PopupWindow.INPUT_METHOD_NEEDED);
Button button1 = contentView.findViewById(R.id.stop_yes);
button1.setOnClickListener(ccc);
TextView textView = contentView.findViewById(R.id.stop_mgs);
pWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
pWindow.setOnDismissListener(new android.widget.PopupWindow.OnDismissListener() {
    @Override
    public void onDismiss() {
        backgroundAlpha(1f);
    }
});
hideBottomUIMenu();//
//是不是需要在showAtLocation后调用才能失效,没有测试

}







猜你喜欢

转载自blog.csdn.net/ink_s/article/details/80985943