- View keyboardView = LayoutInflater.from(activity).inflate(R.layout.random_keyboard, null);
- popupWindow = new PopupWindow(keyboardView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,false);
- //设置点击窗口外边窗口消失
- popupWindow.setOutsideTouchable(false);
- // 设置此参数获得焦点,否则无法点击
- popupWindow.setFocusable(true);
- // popupWindow.setBackgroundDrawable(new BitmapDrawable()); //comment by danielinbiti,如果添加了这行,那么标注1和标注2那两行不用加,加上这行的效果是点popupwindow的外边也能关闭
- keyboardView.setFocusable(true);//comment by danielinbiti,设置view能够接听事件,标注1
- keyboardView.setFocusableInTouchMode(true); //comment by danielinbiti,设置view能够接听事件 标注2
- keyboardView.setOnKeyListener(new OnKeyListener(){
- @Override
- public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
- if (arg1 == KeyEvent.KEYCODE_BACK){
- if(popupWindow != null) {
- close();
- }
- }
- return false;
- }
- });