小编典典

如何在启动时自动显示软键盘?

EditText

我有一个只有 EditText 的活动。我希望软键盘自动显示。我怎样才能做到这一点?


阅读 317

收藏
2022-05-20

共1个答案

小编典典

你可以使用这个 onResume:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(((EditText) findViewById(R.id.your_view)),InputMethodManager.SHOW_FORCED);

我建议您在强制键盘出现之前检查是否有硬件键盘。

隐藏:

((InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.YOUR_VIEW).getWindowToken(), 0);

编辑:

试试这个:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
2022-05-20