How to open Keyboard on Button click in android?

泄露秘密 提交于 2019-12-22 04:21:26

问题


How can I open Keyboard on Button click in android?

What I want to be like this:


回答1:


Please try this

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);



回答2:


InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);

imm.showSoftInput(view, flags)

an example may be:

InputMethodManager imm = (InputMethodManager) RouteMapActivity.this
    .getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mapView, InputMethodManager.SHOW_IMPLICIT);



回答3:


Write this code inside the Button click event to TOGGLE the keyboard:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);


来源:https://stackoverflow.com/questions/8078004/how-to-open-keyboard-on-button-click-in-android

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