android Popupwindow软键盘与窗体重叠的解决方法

来源:互联网 发布:java创建一个表格 编辑:程序博客网 时间:2024/06/16 11:36

在使用Popupwindow时我们经常会碰到软键盘与窗体重叠,解决办法很简单,如下


设置:

//设置弹出窗体需要软键盘popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);//设置模式,和Activity的一样,覆盖,调整大小popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);



注意着两句代码的位置:

private void showStripePayCardInfoDialog() {View view=getLayoutInflater().inflate(R.layout.dialog_stripe,null);        popupWindow=new PopupWindow(view, ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.WRAP_CONTENT,true);        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);                        ColorDrawable colorDrawable=new ColorDrawable(getResources().getColor(R.color.gray));        popupWindow.setBackgroundDrawable(colorDrawable);        popupWindow.showAtLocation(getLayoutInflater().inflate(R.layout.activity_payment_order,null), Gravity.CENTER,0,0);        backgroundAlpha(0.5f);                        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {            @Override            public void onDismiss() {                backgroundAlpha(1.0f);            }        });

为保险起见,最好放在设置完 new popupwindow 下面,一定要注意,否则可能会无效!


0 0