How to launch a PopupWindow or Dialog from an input method service?

后端 未结 1 1709
北恋
北恋 2020-12-15 00:37

I get the same exception when I try to pop a PopupWindow (or Dialog) from InputMethodService:

FATAL EXCEPTION: main
android.view.WindowManager$BadTokenExcept         


        
1条回答
  •  借酒劲吻你
    2020-12-15 01:25

    Actually i managed to do it try this:

     AlertDialog.Builder builder = new AlertDialog.Builder(this);
                     builder.setTitle("Make your selection");
                     builder.setItems(items, new DialogInterface.OnClickListener()
                     {
                        public void onClick(DialogInterface dialog, int item)
                        {
                           // Do something with the selection
                        }
                     });
                     AlertDialog alert = builder.create();
                     Window window = alert.getWindow();
                     WindowManager.LayoutParams lp = window.getAttributes();
                     lp.token = mInputView.getWindowToken();
                     lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
                     window.setAttributes(lp);
                     window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                     alert.show();
    

    0 讨论(0)
提交回复
热议问题