请尝试以下逻辑来隐藏键盘自动打开。
尝试将您的编辑文本置于单独的线性布局中并设置android:focusableInTouchMode="true"
。这将自动避免键盘自动打开。
<LinearLayout
android:id = "@+id/layout"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:focusable = "true"
android:focusableInTouchMode = "true">
<EditText
android:id = "@+id/edit_text"
android:layout_width = "match_content"
android:layout_height = "wrap_content"/>
</LinearLayout>
或者如果上述失败,使用下面的代码以编程方式隐藏。把它写成一个单独的函数并在代码中调用它。
在创建视图后,在您的片段中调用此方法,如下所示。
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
hideKeyboard();
}
public void hideKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
activity.getCurrentFocus()
.getWindowToken(), 0);
} // hideKeyboard
好运..!
do y ou把它修好了 –
可以请你发布你的XML吗? –