Q: A page (with an attachment) contains a search box and a map. When a program jumps to this page, it automatically locates and displays some specified information. However, click the input box, the keyboard does not start. The cause remains unknown. It may be that the focus cannot be obtained by the input box when you jump to this page, but the configured listener can be executed and cannot be understood.
Try a solution, listen to the input box, and manually enable the keyboard. solution 1: Encapsulation Method
[Java]
KeyBoardUtil. showKeyBoard (Activity );
[Java] view plaincopy
/**
* Display the keyboard
* @ Param activity
*/
Public static void showKeyBoard (Activity activity ){
Try {
InputMethodManager imm = (InputMethodManager) activity. getSystemService (Context. INPUT_METHOD_SERVICE );
If (imm! = Null ){
View view = activity. getCurrentFocus ();
If (view! = Null ){
Imm. showSoftInputFromInputMethod (view. getWindowToken (), 0 );
Imm. toggleSoftInputFromWindow (view. getWindowToken (), 0, InputMethodManager. HIDE_NOT_ALWAYS );
}
}
} Catch (Exception e ){
}
}
This method can only be called when you enter the interface for the first time. When you jump to another interface and then return, the keyboard does not work properly.
You can directly use the following method in the listener to modify the scheme:
[Java]
InputMethodManager imm = (InputMethodManager) NearVenueActivity. this. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );
This is the case that the keyboard can be restarted every time, but the keyboard blinks. The reason may be that the keyboard is restarted repeatedly, and the system determines that the keyboard is restarted again.
Finally, find the solution:
[Java]
/**
* Solve the problem that the keyboard cannot be started.
*/
EtSearchVenue. setOnTouchListener (new OnTouchListener (){
@ Override
Public boolean onTouch (View v, MotionEvent event ){
WindowManager. LayoutParams params = getWindow (). getAttributes ();
If (event. getAction () = MotionEvent. ACTION_UP &&
Params. softInputMode! = WindowManager. LayoutParams. SOFT_INPUT_STATE_VISIBLE ){
InputMethodManager imm = (InputMethodManager) NearVenueActivity. this. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );
}
Return true;
}
});
The keyboard cannot be called in this case, but the reason is unknown.