取消手指后,android自定义键盘从弹出窗口中选择一个键

时间:2019-05-06 12:23:02

标签: android android-softkeyboard custom-keyboard soft-keyboard android-custom-keyboard

我想在弹开手指时检测弹出窗口中的按钮。

我想要弹出窗口,例如AOSP或a.i.type键盘。

这是我显示弹出窗口的代码。

@Override
public void onPress(int i) {
    View custom = LayoutInflater.from(this).inflate(R.layout.popupkey, new FrameLayout(this));
    final PopupWindow popup = new PopupWindow(this);
    popup.setContentView(custom);
    popup.setWidth(FrameLayout.LayoutParams.WRAP_CONTENT);
    popup.setHeight(FrameLayout.LayoutParams.WRAP_CONTENT);
    popup.showAtLocation(keyboardView, Gravity.NO_GRAVITY, 0, 0);

    keyboardView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if(popup != null && motionEvent.getAction() == MotionEvent.ACTION_UP) {
                popup.dismiss();
            }
            return false;
        }
    });
}

0 个答案:

没有答案