Android provides the Windowsoftinputmode property to control the interaction of the Input Method Soft Keyboard window and the Activity main window, divided into window resizing series and input method soft keyboard display control series.
Window Sizing Series:
This series of parameters is used to control the adjustment strategy of the Activity main window when the soft keyboard is bouncing, because if the main window is not resized, it is likely that the current input control will be obscured by a soft keyboard.
Adjustpan:
The activity's main window does not resize to make room for the input method, but the contents of the window will automatically scroll up and down to ensure that the currently focused control is not obscured by the keyboard, and then the user can see what they have entered. It is not very satisfying compared to the adjustresize mode, because the user must close the input method to interact with the control that is being masked by the input.
Adjustresize:
The activity's main window is resized to make room for the input method.
Adjustunspecified:
The current mode does not explicitly specify that Activity uses Adjustpan or adjustresize, and the system automatically chooses a pattern, and the result is that if there is a control in the current activity Window that can scroll its contents, such as ScrollView, The result of the selection is adjustresize because it considers scrolling to make the contents of the Window visible even in a small area. The default mode of Activity is this mode.
Adjustnoting:
There is no change in the Activity Window.
In both modes, the relationship between the screen-main window-main window Content-Soft keyboard is as follows:
The specific results are as follows:
No scrolling content, Adjustpan:
No scrolling content, Adjustresize:
No scrolling content, adjustunspecified = = Adjustpan
With scrolling content (ScrollView), Adjustpan
With scrolling content (ScrollView), adjustresize
With scrolling content (ScrollView), adjustunspecified = = Adjustresize
Input Method soft Keyboard Display control series:
This series of parameters is used to control the display or hiding strategy of a soft keyboard when an object containing Window (Activity, dialog, etc.) is displayed at the front of the screen.
Stateunspecified:
The system chooses the corresponding mode according to the current situation.
Stateunchanged:
The soft keyboard retains its previous state (the state of the soft keyboard when the previous activity or Dialog is in the front of the screen), and does not change, regardless of whether the previous state is displayed or hidden.
Statehidden:
The soft keyboard is hidden when the user actively enters the current interface. Leave the previous interface and return to the current interface, which cannot be counted as an "active entry". When passive entry, keep the previous state.
Statealwayshidden:
As long as the user enters the interface, it hides the soft keyboard, whether it is active (new to start the interface) or passive (leaving the previous interface to return to the current interface).
Statevisible:
The soft keyboard is displayed when the user actively enters the current interface. Leave the previous interface and return to the current interface, which cannot be counted as an "active entry". When passive entry, keep the previous state.
Statealwaysvisible:
As long as the user enters the interface, the soft keyboard is displayed, whether the active entry (new start of the interface), or passive entry (leaving the previous interface, return to the current interface).
A bug about some Huawei phones
Encountered a bug today, in some Huawei phones above, in addition to the first click on the input box, the Adjustpan parameter will take effect (the soft keyboard can play the input box normally), after the second start, how to click, adjustpan parameters are invalid.
The layout model is roughly as follows:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:id=" @+id/activity_main "android:layout_width=" Match_parent "Android:layout_hei ght= "Match_parent" tools:context= "cn.hjf.inputtest.MainActivity" > <scrollview android:layout_width= "Mat Ch_parent "android:layout_height=" match_parent "> <linearlayout android:layout_width=" Match_ Parent "android:layout_height=" match_parent "android:orientation=" vertical "> <view Android:layout_width= "Match_parent" android:layout_height= "400DP" Android:bac kground= "#2b532b"/> <edittext android:layout_width= "90DP" android:layout_he ight= "Wrap_content" android:layout_gravity= "center_vertical" android:background= "@null" android:gravity= "Center" Android:inputtype= "Numberdecimal" android:maxlength= "8" android:minwidth= "60DP" android:padding= "5DP" android:text= "0.00"/> </LinearLayout> </scrollview& Gt;</relativelayout>
The effect is this:
After a long time of elimination (very hard), finally found the trigger point of the bug, is the following two words:
android:gravity= "center" android:inputtype= "Numberdecimal"
After a long time of verification, it came to a conclusion: on some Huawei models, in this layout model, if the InputType parameter (not none) is set in EditText, then the problem occurs when the value of gravity is worth something. The general situation is as follows:
Red indicates invalid, green indicates active (works correctly). When these two parameters are not specified, you can work because the combination of the default values of these two properties is the blue block that can work in. (Note: There is no exact match in all cases, if there is a similar situation, you can match on demand to see the results)
The default values for these two properties can be found in the source code:
Attrs.xml
<!--Default EditText style. -- <attr name= "Edittextstyle" format= "Reference"/>
Themes.xml
<item name= "Edittextstyle" > @style/widget.edittext</item>
Styles.xml
<style name= "Widget.edittext" > <item name= "focusable" >true</item> <item name= " Focusableintouchmode ">true</item> <item name=" clickable ">true</item> <item name= "Background" >?attr/editTextBackground</item> <item name= "Textappearance" >?attr/ textappearancemediuminverse</item> <item name= "TextColor" >?attr/editTextColor</item> <item name= "Gravity" >center_vertical</item> <item name= "Breakstrategy" >simple</item> <item name= "Hyphenationfrequency" >normal</item>
Attrs.xml
<!--the type of data being placed in a text field, used-to-help an input method decide the user enter T Ext. The constants here correspond to those defined by {@link Android.text.InputType}. Generally can select a single value, though some can be combined together as indicated. Setting this attribute to anything besides <var>none</var> also implies, the text is editable.-->< C9/><attr name= "InputType" > <!--There is no content type. The text is not editable. -- <flag name= "None" Value= "0x00000000"/>
/** * Special Content type for if no explicit type has been specified. * This should being interpreted to mean that the target input connection * are not rich, it can not process and show thing s like candidate text nor * Retrieve the current text, so the input method would need to run in a * limited "genera Te key Events "mode, if it supports it. Note that some * input methods could not support it, for example a voice-based input * method would likely not be ABL E to generate key events even if this * flag is set. */public static final int type_null = 0x00000000;
A requirement
Encountered a requirement, the approximate model is: There is an interface, there is an input box and two buttons, respectively, control the input box number of the addition and subtraction, as shown in:
Each time the input box number changes, whether it is the manual input or the button control, will start to refresh the work, the refresh will pop up a dialog box.
Then the demand is this, when the manual input, when the trigger refresh, the input method is displayed, but the dialog box appears and then disappears, the input method is hidden. When using the button control, it is not a problem, because the whole process, the input method is hidden. So the requirement is that when the dialog box is displayed and then disappears, the input method can maintain the state of the start refresh.
Solve the problem: when the current Activity is set to stateunchanged, it does not achieve the desired effect, because dialog is located in the window, the property is not set, So the dialog window needs to be set to Stateunchanged, as follows:
GetWindow (). Setsoftinputmode ()
And then it's ready.
Android Soft Keyboard control methods, as well as some problems encountered in the development.