Android adjustresize Full Screen Invalid issue

Source: Internet
Author: User

Screen mode, even if the activity's Windowsoftinputmode property is set to: adjustresize, it does not push the activity's screen upward while the keyboard is displayed, So the size of the root tree of your activity's view is unchanged. In this case, you will not know the size of the keyboard, the root view of the corresponding changes. The problem that the keyboard can't resize in full screen has existed since 2.1, and Google hasn't solved it yet.
The following classes can be used to solve this problem:
 Public classAndroidbug5497workaround {//For more information, seehttps://code.google.com/p/android/issues/detail?id=5497    //to use the This class, the simply Invoke Assistactivity () on the Activity that already have its content view set.     Public Static voidassistactivity (activity activity) {NewAndroidbug5497workaround (activity); }    PrivateView mchildofcontent; Private intusableheightprevious; PrivateFramelayout.layoutparams Framelayoutparams; PrivateAndroidbug5497workaround (activity activity) {Framelayout content=(framelayout) Activity.findviewbyid (Android.        R.id.content); Mchildofcontent= Content.getchildat (0); Mchildofcontent.getviewtreeobserver (). Addongloballayoutlistener (NewViewtreeobserver.ongloballayoutlistener () { Public voidongloballayout () {possiblyresizechildofcontent ();        }        }); Framelayoutparams=(Framelayout.layoutparams) mchildofcontent.getlayoutparams (); }    Private voidpossiblyresizechildofcontent () {intUsableheightnow =computeusableheight (); if(Usableheightnow! =usableheightprevious) {            intUsableheightsanskeyboard =Mchildofcontent.getrootview (). GetHeight (); intHeightdifference = Usableheightsanskeyboard-Usableheightnow; if(Heightdifference > (USABLEHEIGHTSANSKEYBOARD/4)) {                //keyboard probably just became visibleFramelayoutparams.height = Usableheightsanskeyboard-heightdifference; } Else {                //keyboard probably just became hiddenFramelayoutparams.height =Usableheightsanskeyboard;            } mchildofcontent.requestlayout (); Usableheightprevious=Usableheightnow; }    }    Private intcomputeusableheight () {Rect R=NewRect ();        Mchildofcontent.getwindowvisibledisplayframe (R); return(R.bottom-r.top); }}
How to use: Call Androidbug5497workaround.assistactivity (this) in your activity's OnCreate () method; Note: Called after Setcontentview (r.layout.xxx).

Android adjustresize Full Screen Invalid issue

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.