在应用程序加载时隐藏软键盘

新手上路,请多包涵

我有一个主视图上带有 EditText 元素的应用程序。这意味着当我的应用程序加载时,软键盘默认出现。

我希望能够在加载时隐藏键盘,因此在我点击 EditText 视图之前它不会显示。

我该如何管理?

原文由 Esben Andersen 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 281
2 个回答

你可以做一些更容易的事情。将其添加到 LinearLayout(或作为根的任何其他布局):

 <LinearLayout
...
android:focusable="true"
android:focusableInTouchMode="true"
...
/>

原文由 neteinstein 发布,翻译遵循 CC BY-SA 3.0 许可协议

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

这将在所有情况下隐藏(即使 EditView 具有焦点):

  EditText editView = (EditText) findViewById(R.id.editTextConvertValue);
 editView.setInputType(InputType.TYPE_NULL);

原文由 John Cooper 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题