自动显示键盘

自动显示键盘,第1张

自动显示键盘

我认为这是一个bug或一项功能,试图向您展示整个活动,而不会首先用软键盘掩盖它。我曾经搜索过有关该信息的信息,但不幸的是,没有发现任何来自可靠来源的信息。

无论如何,要显示软键盘,您可以执行以下 *** 作

EditText editText = (EditText)findViewById(R.id.edit_text_id);InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

我还看到了以下代码,该代码应强制在活动开始后立即显示软键盘,但从未尝试过:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

如果要隐藏软键盘,可以执行以下 *** 作:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

希望能有所帮助。

编辑:

对于

DialogFragment
这应该工作:在
onCreateView()
方法中执行此 *** 作:

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,        Bundle savedInstanceState) {    View view = inflater.inflate(R.layout.fragment_id, container);    EditText editText = (EditText)view.findViewById(R.id.edit_text_id);    // show soft keyboard    editText.requestFocus();    getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);    return view;}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5488731.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存