Some minor problems with the android soft keyboard

There are many uses of the soft keyboard in Android. The following are the commonly used settings of the soft keyboard;

1. When the screen is horizontal, click the input box to display the full keyboard solution: add in EditText, searchview and other controls

?

1

android:imeOptions="flagNoExtractUi"

2. When the screen is vertical, Android will display a half screen.

case1: Your input box is in the middle and bottom position. In this case, the keyboard may block the input box. Solution: Set the activity in the manifest

?

1

android:windowSoftInputMode="adjustResize"

In this way, the main window of the activity will always resize to provide space for the keyboard

case2: Your input box is on the upper side. Under normal circumstances, there will be no problem, but if your interface uses layout_weight, that is, specific gravity to distribute pages in the vertical direction, the software disk will compress the entire window, resulting in part of the input box Be compressed. Solution: Set the activity in the manifest

?

1

android:windowSoftInputMode="adjustPan"

In this way, the keyboard will not compress the original window, but only cover part of the content below. In this way, the input box will not be compressed.

3. Just enter an activity, focus input box, then will automatically pop up the soft keyboard, if you do not want to automatically pop up, you can first let other unimportant controls get focus, then a timer and then let EditText get focus !

4. Determine whether the soft keyboard is currently in the pop-up state

?

1

if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)

5. Manually hide the soft keyboard

?

1

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

6. Manually pop up the soft keyboard

?

1

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);

Published 10 original articles · Like 11 · Visits 20,000+

Guess you like

Origin blog.csdn.net/u013323018/article/details/83186056