About the edittext focus and keyboard in Android:
Usually in a layout, set the focus mode for edittext as follows. After the activity is started, the focus is automatically positioned to the first edittext and the keyboard automatically pops up.
Method 1: In layout:
Android: focusable = "true" Android: focusableintouchmode = "true"
Method 2:CodeMedium:
Edit. setfocusable (true );
If you do not need to enable the automatic pop-up keyboard, set the property Android: windowsoftinputmode = "statealwayshidden" (or statehidden | adjustresize) in the activity tag of the manifest file)
Set as needed to prevent the keyboard from being automatically popped up.
But if you wantEvent triggeringTo bring up the keyboard (for example, when switching from voice to text), you need to bring up the keyboard automatically.
The specific method is as follows:
Edit. requestfocus (); inputmethodmanager Imm = (inputmethodmanager) EDIT. getcontext (). getsystemservice (context. input_method_service); Imm. togglesoftinput (0, inputmethodmanager. show_forced );
The above code consists of two parts: the first step is to get the focus through the requestfocus () method (setfocusable (true) does not know why it is invalid );
The second step is to force the keyboard to pop up. Because the focus is on edittext, the input is normal.