I design the login page as:
UserName: ..... Password: ..... LoginButton
When the action starts, I want the focus to move to the "UserName" text box and the keyboard will appear.
I am using the following code:
boolean checkFocus=user.requestFocus(); Log.i("CheckFocus", ""+checkFocus); if(checkFocus==true) { InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(user, InputMethodManager.SHOW_IMPLICIT); }
I donβt understand where to write this code so that the keyboard is displayed when the activity starts and focuses in the "UserName" editing window. Can anyone guide me?
android android-layout android-edittext
Kanika Nov 10 2018-11-11T00: 00Z
source share