简体   繁体   中英

Android soft keyboard showing under a dialog fragment

I have a dialog fragment, which has a listview with mutiple views listed, in one of that view there is an edittext which has showing cursor, but soft keyboard is not showing. So i write a code on its onclick to show keyboard like below,

etcomment.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                }
            });

Now keyboard is showing, but it is showing under that DialogFragment

在此处输入图片说明

I searched but didn't get an answer, please help me!

Your window params is the problem Okay u should do like this:..

    Dialog dialog = new Dialog(DialogTestKeyboard.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width  = 400;
    lp.height = 800;
    dialog.setContentView(yourLayoutHavingEditText);
    dialog.setCancelable(false);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();
    dialog.getWindow().setAttributes(lp);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM