简体   繁体   English

在加载片段时隐藏软键盘或虚拟键盘

[英]To Hide soft keyboard or virtual keyboard on loading the fragment

我的片段中有2个编辑文本框。无论何时通过任何活动加载此片段,软键盘都会出现在屏幕上,从而覆盖平板电脑屏幕的一半。我想在任何活动加载片段时隐藏软键盘。软键盘应仅在单击或点击编辑文本框时出现。

Padma's comment will prevent the soft keyboard from EVER coming up in the application, which it doesn't sound like you want since you have EditText's that need to get their input from somewhere. Padma的评论将阻止软键盘在应用程序中出现,这听起来不像你想要的,因为你有EditText需要从某个地方获取他们的输入。

You could just close the soft keyboard for whichever EditText is on that view when it's loading: 你可以关闭软键盘,以便加载时该视图上的EditText:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(findViewById(R.id.your_edit_text).getWindowToken(), 0);
getActivity().getWindow().setSoftInputMode(
              WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

对于DialogFragment,您必须从对话框中删除焦点,而不是从DialogFragment中的第一个EditText

this.getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

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

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