When we write modification information or search, change the password and other interface, the main purpose of the user to enter this interface is to input modify/find some information, in order to user experience should automatically eject the soft keyboard instead of letting the user actively click the input box to pop up.
1. Automatic popup of Soft keyboard
privatevoidshowKeyboard(){ InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 0); }
When the interface is more complex, the soft keyboard may not eject properly and need to be loaded lazily. That is, after the interface loading is complete, the soft keyboard pops up
- 1.1 Using the Timer schedule
new Timer(); timer.schedule(new TimerTask() { publicvoidrun() { InputMethodManager inputManager = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 0); } 998);
2. Soft keyboard off
I have encountered a situation is that the home page is ScrollView wrapped interface, rolling a distance into the next page, will pop up the soft keyboard, when the interface is closed (that is, direct finish ()), back to the home page, ScrollView is not the original position. The solution is to have a soft keyboard pop-up page, first off the soft keyboard, then the finish () interface.
privatevoidcloseKeyboard() { View view = getWindow().peekDecorView(); ifnull) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 0); } }
3. The soft keyboard to squeeze some layout up the situation
<activity android:name=".activity.DetailActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan" android:theme="@style/AppTheme.NoActionBar.Translucent"/>
This property is mainly Windowsoftinputmode, of which 2 of the more important are adjustpan and adjustresize
Adjustpan does not squeeze the bottom layout, such as the layout of the bottom in the relatelayout layout
The adjustresize is self-adapting and will squeeze the bottom up.
More detailed can understand the next windowsoftinputmode this attribute, a lot of great God's blog has a description, I do not repeat.
Android soft Keyboard Auto Eject and close