
我认为这是一个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;}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)