Android Monitor keyboard display and hide

Source: Internet
Author: User

Problem Profile: Horizontal Board COCOS2DX game, click the input box pop-up keyboard, interface requirements to follow the online, can not block the input box. This problem only occurs in non-full-screen keyboards to the case.

Scheme 1:mainactivity rewrite onconfigurationchanged, monitor screen orientation rotation, add android:configchanges= "Orientation|keyboard".

Disadvantage full screen invalid, if set to non-full screen, <activity android:theme= "@android: Style/theme.notitlebar.fullscreen"/>, remove fullscreen

This will display the system status bar. No, drop it!

Scenario 2: Pop-up keyboard will cause layout changes, monitoring layout changes and then calculate the offset, you can figure out whether to show or hide the keyboard.

Global keyboard display and hide does not trigger

Add layout change monitoring Root.getviewtreeobserver (). Addongloballayoutlistener (New Ongloballayoutlistener () {              @Override              public void Ongloballayout () {                  rect rect = new Rect ();                  Root.getwindowvisibledisplayframe (rect);                  int rootinvisibleheight = Root.getrootview (). GetHeight ()-Rect.bottom;                  if (Rootinvisibleheight <=) {                     //notify C + + to do what you want                hidekeyboardhandler ();                } else {                Showkeyboardhandler ();                }            }          

Android Monitor keyboard display and hide

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.