键盘隐藏了AutoCompleteTextView下拉菜单 [英] Keyboard hides AutoCompleteTextView dropdown

查看:200
本文介绍了键盘隐藏了AutoCompleteTextView下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DialogFragment的底部有一个AppCompatAutoCompleteTextView.

在横向模式下的平板电脑(API 19)上,当建议列表中只有一个元素时,下拉菜单将由键盘覆盖.当元素更多时,下拉列表将向上显示,并且可以正常工作.

On tablet (API 19) in landscape mode the dropdown is covered by the keyboard when there is only one element in the suggestion list. When there are more elements, the dropdown goes upwards, and works fine.

在移动设备(API 22)上,即使建议列表中只有一个元素,也不会出现任何问题,下拉列表始终显示为向上.

On mobile (API 22), there aren't any problems even when there's only one element in the suggestion list, the dropdown is always shown upwards.

我已经在清单中的活动中添加了android:windowSoftInputMode="adjustPan|stateHidden".

I've already added android:windowSoftInputMode="adjustPan|stateHidden" to the activity in the Manifest.

如何使下拉菜单始终向上或不被键盘覆盖?

How can I make the dropdown always go upwards or not to be covered by the keyboard?

推荐答案

 dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                try {
                    if (view != null) {
                        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(mContext.INPUT_METHOD_SERVICE);
                        if (!imm.hideSoftInputFromWindow(autoCompleteTextView.getWindowToken(), WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)) {
                            //call dialog dismiss code here
                        }
                    }
                } catch (Exception e) {
                    ExceptionUtils.logException(e);
                }
            }
            return false;
        }
    });

当键盘关闭时,

hideSoftInputFromWindow返回true,否则返回false.因此,在第一次后按时,它将关闭键盘,在第二次后按时,它将进入状态并关闭对话框

hideSoftInputFromWindow returns true when keyboard is closed else false. So in first back press it'll close keyboard and in second back press it'll go in if condition and dismiss dialog there

这篇关于键盘隐藏了AutoCompleteTextView下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆