Remember when the keyboard pops up when the page has EditText

Take a look at this property in the Activity in the Manifest file

android:windowSoftInputMode="adjustPan|stateHidden"
Copy the code

The following introduction is part of the official documentation

This property was introduced after Android 1.5 and is mainly used for activities to interact with the soft keyboard. There are two main functions:

  • The state of the soft keyboard – hidden or visible – when the Activity becomes the focus of the user’s attention.
  • Changes made to the Activity’s main window – whether to reduce its size to make room for the soft keyboard, or whether to pan its contents to make the current focus visible when part of the window is obscured by the soft keyboard.

This setting must be one of the values listed in the following table, or a “state…” Value plus a “adjust…” Combination of values. Set multiple values in either group (for example, multiple “state…” Value) produces undefined results. The values are separated using the vertical bar (|).

The idea here is that normal has the following combinations

  1. adjust…
  2. adjust… +state…
  3. state…

Instead of writing

  • adjust…
  • state…

Such as

<activity android:windowSoftInputMode="stateVisible|adjustResize"... >Copy the code

Properties:

  1. StateUnspecified: Does not specify the state of the soft keyboard (hidden or visible). It is up to the system to select the appropriate state, or to rely on Settings in the topic. This is the default setting for soft keyboard behavior.
  2. StateUnchanged: When the activity comes up, the soft keyboard stays the same as the previous activity, hidden or displayed
  3. StateHidden: The soft keyboard is always hidden when the user selects to open a new activity, and the default is used when returning from another activity. Hide the soft keyboard when the user selects the Activity – that is, when the user actually navigates forward to the Activity, rather than returning from leaving another Activity.)
  4. StateAlwaysHidden: The soft keyboard is always hidden when the Activity main window gets focus
  5. StateVisible: Displays the soft keyboard under normal and appropriate conditions (when the user navigates forward to the main window of the Activity).
  6. StateAlwaysVisible: Displays the soft keyboard when the user selects an Activity – that is, when the user is actually navigating forward to the Activity, rather than returning from leaving another Activity.
  7. AdjustUnspecified: This is the default setting. It is usually up to the system to decide whether the main window of the Activity is resized to make room for the soft keyboard, or whether the window content is shifted to show the current focus on the screen. The system automatically selects one of these modes based on whether there are any layout views for scrolling the contents of the window. If such a view exists, the window will be resized, provided that the entire contents of the window can be seen in a small area by scrolling. This is the default setting for the main window behavior.
  8. AdjustResize: The Activity always adjusts the screen size to make room for the soft keyboard
  9. AdjustPan: The contents of the current window will automatically move so that the current focus is never covered by the keyboard and the user can always see the input parts. Instead of resizing the Activity’s main window to make room for the soft keyboard, the content of the window is automatically panted so that the current focus is never obscured by the keyboard and the user can always see what they are typing. This is usually not as desirable as sizing, since the user may need to close the soft keyboard to reach or interact with obscured window parts.)

I have a problem

I click the button on the home page to enter the next page. After entering the page, the soft keyboard will pop up automatically. There are two ways to return to the home page

Methods a

Press the return key, fold up the soft keyboard first, press again, return to the home page, this situation is no problem

Way 2

Click the back button in the navigation bar directly to return to the home page. This case does return to the home page, but the soft keyboard does not automatically collapse. The Activity on my home page is set

android:windowSoftInputMode="adjustPan|stateHidden"
Copy the code

These two properties are set because there is an input field on the main page. If not set, the input field will pop up to the bottom TAB bar.

AdjustPan is normal according to the above attribute description. It can solve the problem that when THE keyboard pops up, the bottom TAB bar comes to the top.

Because I’m on the home screen, the soft keyboard is hidden when I first enter ActivityA. If I go to ActivityA from the home screen, there’s an input box in ActivityA, and I click the back button in the upper left corner to go back to the home screen, the soft keyboard is not hidden. Or is it on the page,

Final solution:

Since this is the main page, we want the soft keyboard to be hidden every time we come in, just change stateHidden to stateAlwaysHidden or delete it.

You can follow me in the following ways:

  1. CSDN
  2. The Denver nuggets
  3. Personal blog
  4. Github