Method of Android prohibiting EditText from automatically ejecting soft keyboard and problems encountered
- 2021-09-20 21:22:44
- OfStack
Usually encountered in the development of very small problems, here to record 1.
Added in AndroidManifest. xml as in AndroidManifest
android:windowSoftInputMode="adjustResize"
Or adjustPan, the EditText control included in the page will automatically pop up the software disk when it enters.
1. Add in the parent layout that contains EditText
android:focusable="true"和android:focusableInTouchMode="true"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
/>
</LinearLayout>
This prevents the automatic ejection of the soft keyboard
2. Add stateHidden to AndroidManifest. xml so that it does not pop up automatically
<activity android:name=".TestAActivity"
android:windowSoftInputMode="adjustResize|stateHidden">
</activity>
3. Enter the page to force the soft keyboard to be hidden
If neither of the first two methods works, you can use this method:
/**
* Hide input soft keyboard
* @param context
* @param view
*/
public static void hideInputManager(Context context,View view){
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (view !=null && imm != null){
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // Forced hiding
}
}
Summarize