How to monitor the open and close of Android soft keyboard

Source: Internet
Author: User

This yesterday wrote pretty close, too laborious, at present not I think better way to solve.

Also consulted a lot of friends of the information and blogs, but has not finished the effects I need.

Finally helpless use the following method:

1  Public classInputstatelinearlayoutextendslinearlayout{2     PrivateOnsizechangedlistener Listener;3 4      PublicInputstatelinearlayout (Context context) {5         Super(context);6     }7 8      PublicInputstatelinearlayout (Context context, AttributeSet attrs) {9         Super(context, attrs);Ten     } One  A      PublicInputstatelinearlayout (context context, AttributeSet attrs,intdefstyleattr) { -         Super(context, attrs, defstyleattr); -     } the  - @Override -     protected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { -         Super. Onmeasure (Widthmeasurespec, heightmeasurespec); +     } -  + @Override A     protected voidOnLayout (BooleanChangedintLintTintRintb) { at         Super. OnLayout (Changed, L, T, R, b); -     } -  - @Override -     protected voidOnsizechanged (intWintHintOLDW,intOLDH) { -         Super. Onsizechanged (W, H, OLDW, OLDH); in         if(Listener! =NULL) { - listener.onsizechanged (W, H, OLDW, OLDH); to         } +     } -  the      Public voidSetonsizechangedlistener (Onsizechangedlistener listener) { *          This. Listener =Listener; $     }Panax Notoginseng  -     /*** Callback interface when the activity main window size changes (this example is equivalent to the soft keyboard display is hidden when the callback interface)*/ the      Public InterfaceOnsizechangedlistener { +          Public voidOnsizechanged (intWintHintOLDW,intOLDH); A     } the}

The above code does not say much, continue on the code:

1Mroot.setonsizechangedlistener (NewInputstatelinearlayout.onsizechangedlistener () {2 @Override3              Public voidOnsizechanged (intWintHintOLDW,intOLDH) {4              if(H>OLDH) {//Close5                //the logic you need to handle yourself.6              }7             }8});

Mroot is actually the root layout of this interface. Self-test, H>OLDH is closed and vice versa.

The above has temporarily completed my needs.

And then I used it, listening.

Viewtreeobserver

Although it is also possible, but it does not meet my needs.


Reprint please specify the source!

How to monitor the open and close of Android soft keyboard

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.