How to automatically show soft keyboard on start?

纵饮孤独 提交于 2019-12-06 09:55:15

问题


I have an activity that only has a EditText. I want the soft keyboard to show up automatically. How can I do this?


回答1:


You can use this onResume:

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

I suggest that you check if there is a Hardware keyboard before you force the keyboard to appear.

To hide:

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

EDIT:

Try this:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);


来源:https://stackoverflow.com/questions/6100791/how-to-automatically-show-soft-keyboard-on-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!