Show hidden on Android soft keyboard

Source: Internet
Author: User

first, the principle of soft keyboard display
What is the nature of the software disk? The soft keyboard is actually a dialog!
Inputmethodservice created a dialog for our input method and set some parameters of the dialog window, such as gravity, to be displayed at the bottom or full screen. When we click on the input box, the system adjusts the active main window to make room for the input method, and then displays the dialog at the bottom or full screen.

Second, the main window of the activity adjustment
Android defines a property named Windowsoftinputmode, which allows the program to control how the active main window adjusts. We can set the activity in Androidmanifet.xml. such as: android:windowsoftinputmode= "Stateunchanged|adjustpan"
The optional value for this property has two parts, one for the soft keyboard state control, and the other for the active main window adjustment. The first part of this article is not discussed, please consult your Android documentation yourself.

Mode one, compression mode
If the value of Windowsoftinputmode is set to Adjustresize, the Activity main window is always resized to allow space on the soft keyboard.
We test it with a piece of code, and when we set it up, what the system does when the Input method pops up.
To rewrite layout layouts:

1  PublicclassResizelayoutextendslinearlayout{2PrivateStaticintCount = 0; 3      4 PublicResizelayout (Context context, AttributeSet attrs) {5Super(context, attrs);6     } 7      8 @Override9protectedvoidOnsizechanged (intWintHintOLDW,intOLDH) {     TenSuper. Onsizechanged (W, H, OLDW, OLDH); One           ALOG.E ("onsizechanged" + count++, "=>onresize called! w= "+w +", h= "+h+", oldw= "+oldw+", oldh= "+OLDH);  -     }  -       the @Override -protected voidOnLayout (BooleanChangedintLintTintRintb) { -Super. OnLayout (Changed, L, T, R, b); -LOG.E ("OnLayout" + count++, "=>onlayout called! L= "+ L +", t= "+ t +", r= "+ R +", b= "+b);  +     }  -       + @Override AprotectedvoidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) {  atSuper. Onmeasure (Widthmeasurespec, heightmeasurespec); -           -LOG.E ("onmeasure" + count++, "=>onmeasure called! Widthmeasurespec= "+ Widthmeasurespec +", heightmeasurespec= "+Heightmeasurespec);  -}
Resizelayout

Xml:

<com.winuxxan.inputmethodtest.resizelayout      xmlns:android= "/http Schemas.android.com/apk/res/android "     android:id=" @+id/root_layout "      android:layout_width= "Fill_parent"      android:layout_height= "Fill_ Parent "     android:orientation=" vertical "     >           <EditText          android:layout_width= "Fill_parent"            android:layout_height= "Wrap_content"       />         <LinearLayout              android:id= "@+id/bottom_layout"               android:layout_width= "Fill_pareNT "              android:layout_height=" Fill_parent "              android:o rientation= "Vertical"              android: gravity= "Bottom" >s         <TextView            android:layout_width= "Fill_parent"            android:layout_height= "Wrap_content"            android:text= "@string/hello"           Android:background= "#77777777"        />    </ linearlayout> </com.winuxxan.inputmethodtest.resizelayout> 

Activity setting properties for Androidmanifest.xml: Android:windowsoftinputmode = "Adjustresize"
To run the program, click the text box to view the debug information:
E/onmeasure 6 (7960): =>onmeasure called! widthmeasurespec=1073742144, Heightmeasurespec = 1073742024
E/onmeasure 7 (7960): =>onmeasure called! widthmeasurespec=1073742144, Heightmeasurespec = 1073742025
E/onsizechanged 8 (7960): =>onsizechanged called! w=320,h=201,oldw=320,oldh=377
E/onlayout 9 (7960): =>onlayout called! L=0, t=0,r=320,b=201
From the debug results we can see that when we click on the text box, the root layout calls onmeasure,onsizechanged and OnLayout.
In fact, when set to Adjustresize, the soft keyboard pops up to re-measure and layout the main window layout, while in layout, the size of the window is changed, so onsizechanged is called.
From the results of the operation we can also be seen, originally in the bottom of the TextView was top to the input method above.

Mode two, panning mode

If the value of Windowsoftinputmode is set to Adjustpan, the Activity main window does not resize the screen to allow space on the soft keyboard. Instead, the contents of the current window are automatically moved so that the current focus is never covered by the keyboard and the user can always see the part of the input. This is usually not expected than resizing, because the user may turn off the soft keyboard in order to get an interactive operation with the covered content.
In the example above, we will change the properties of androidmanifest.xml: Android:windowsoftinputmode = "Adjustpan"

Rerun and click the text box to view the debug information:
E/onmeasure 6 (8378): =>onmeasure called! widthmeasurespec=1073742144, heightmeasurespec=1073742200
E/onmeasure 7 (8378): =>onmeasure called! widthmeasurespec=1073742144, heightmeasurespec=1073742201
E/onlayout 8 (8378): =>onlayout called! L=0, t=0,r=320,b=377
We see: The system also re-measrue and layout, but we found that the layout process is not called onsizechanged, which indicates that the input method before and after the popup has not changed the size of the original layout.
From the running results we can see that the textview below is not top to the input method.

In fact, when the input box is not obscured, the pattern does not adjust the layout, but when the input box is obscured, the window pans. That is, the pattern is always to keep the input box visible. For example, the entire window, including the title bar, is moved up to ensure that the text box is visible

Mode three Auto mode
When the property Windowsoftinputmode is set to adjustuspecified, it is not specified whether the Activity main window is resized to allow space for the soft keyboard, or whether the contents of the window are visible on the screen where the current focus is. The system will automatically select one of these modes primarily depending on whether the contents of the window have any layout view that can scroll their content. If there is such a view, the window will be resized so that the contents of the scrolling window can be visible in a smaller area. This is the default behavior setting for the main window.
That is, the system automatically determines whether to use the panning or compression mode, the determining factor is that the content can be scrolled.

Show hidden on Android soft keyboard

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.