简体   繁体   English

键盘正在使用底部工作表对话框片段打开,甚至在 Activity 或 Fragment 中没有 EditText

[英]Keyboard is opening with bottom sheet dialog fragment without even having EditText in Activity or Fragment

I don't know why but Keyboard automatically opens when I open BottomSheetDialogFragment from another fragment.我不知道为什么,但是当我从另一个片段打开 BottomSheetDialogFragment 时,键盘会自动打开。 I tried with both navigation component and old method.我尝试了导航组件和旧方法。 I tried on API 24, 27, 30. On API 30 its working fine but in 24 and 27 facing this issue.我试过 API 24、27、30。在 API 30 上它工作正常,但在 24 和 27 中面临这个问题。 Anyone here who is facing this issue?这里有人遇到这个问题吗? And Anyone who have solution for this problem please post answer.任何对此问题有解决方案的人请发布答案。

this is not the best way to do that but you can use this code to disable the keyboard in your onActivityCreated function in a fragment:这不是最好的方法,但您可以使用此代码在片段中禁用 onActivityCreated function 中的键盘:

InputMethodManager i = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
i.hideSoftInputFromWindow(getView().getWindowToken(), 0);

it is better to find the cause of why the keyboard comes up automatically but you can use this solution if you want.最好找到键盘自动出现的原因,但如果需要,您可以使用此解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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