Android implementation of landing page logo with the keyboard retractable dynamic (perfect solution to the problem of keyboard pop-up occlusion control) _android

Source: Internet
Author: User
Tags gettext visibility

In the last two projects, project requirements require us to implement the/* landing page content to be topped up with the keyboard popping up, to avoid the keyboard blocking the landing button * * This effect, the baby in the heart bitter Ah, was half a day to fix things still have to toss about, well I compromise, after all, I was a very user-oriented ape.

Then do it, the initial plan is the input box and landing button size unchanged, in the keyboard when the size and position of the logo to change, so that the keyboard to make room, of course, when the keyboard is put away to restore it, like nothing happened, um yes, that's it, said so much, Let's take a picture and feel the effect first:

Next dinner, the layout is relatively simple, pay attention to the picture outside a fit linearlayout, because it will depend on it to change the location of the logo, layout code as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height = "Match_parent" android:background= @color/white "tools:context=". Login. Loginactivity "android:orientation=" vertical "android:id=" @+id/ll_login_root "> <linearlayout android:orient ation= "vertical" android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:layout_marginto p= "90DP" android:id= "@+id/ll_login_logobg" android:layout_marginbottom= "50DP" > <imageview android:layou T_width= "160DP" android:layout_height= "160DP" android:id= "@+id/iv_login_logo" android:background= "@mipmap/logi N_logo "android:layout_gravity=" Center_horizontal "/> </LinearLayout> <linearlayout Android:orienta tion= "vertical" android:layout_width= "match_parent" android:layout_height= "Match_parent "android:layout_marginleft=" 50DP "android:layout_marginright=" 50DP "> <linearlayout Android 
    : orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "50DP" > <ImageView Android:layout_width= "45DP" android:layout_height= "45DP" android:background= "@mipmap/login_phone" Andro Id:id= "@+id/imageview2" android:layout_gravity= "bottom"/> <edittext android:layout_width= "Match_paren" T "android:layout_height=" wrap_content "android:inputtype=" Phone "android:ems=" "android:id=" @+id/et _login_phone "android:layout_gravity=" center "android:hint=" please input mobile phone number "android:background=" @null "Android : maxlength= "One"/> </LinearLayout> <linearlayout android:orientation= "vertical" android:layout_wi Dth= "Match_parent" android:layout_height= "1DP" android:background= "@color/text_gray" ></LinearLayout> & Lt LinearLayout Android:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "50DP" > <ImageVi 
    EW android:layout_width= "45DP" android:layout_height= "45DP" android:background= "@mipmap/login_password" Android:id= "@+id/imageview3" android:layout_gravity= "bottom"/> <edittext android:layout_width= "Wrap" _content "android:layout_height=" wrap_content "android:inputtype=" Phone "android:ems=" "android:id=" @+id/et_login_code "android:layout_gravity=" center "android:layout_weight=" 1 "android:hint=" Please enter the verification code "an Droid:background= "@null" android:maxlength= "6"/> <button android:layout_width= "90DP" Android:layo 
    ut_height= "30DP" android:text= "Get Authentication Code" android:textcolor= "@color/white" android:id= "@+id/bt_login_getcode" android:background= "@mipmap/login_button_blue" android:layout_gravity= "center_vertical" android:textSize= "14 DP "/> </linearlayout> <linearlayout android:orientation= "vertical" android:layout_width= "match_parent" Android:layo  
   ut_height= "1DP" android:background= "@color/text_gray" android:layout_marginbottom= "10DP"/> <linearlayout android:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "20DP" Android : id= "@+id/ll_login_warning" android:visibility= "Gone" > <imageview android:layout_width= "25DP" Andr oid:layout_height= "25DP" android:background= "@mipmap/login_warning" android:id= "@+id/imageview" Android:lay out_gravity= "center_vertical"/> <textview android:layout_width= "Wrap_content" Wrap_content "android:textappearance="? Android:attr/textappearancemedium "android:text=" Please enter the verification code "android:id= "@+id/tv_login_wraning" android:layout_gravity= "center_vertical" android:textcolor= "@color/text_red" Androi D:textsize= "13DP"/>
  </LinearLayout> <button android:layout_width= "match_parent" android:layout_height= "40DP" Androi D:textcolor= "@color/white" android:id= "@+id/bt_login_submit" android:background= "@mipmap/login_button_gray" an droid:text= "Login" android:textsize= "18DP" android:layout_margintop= "10DP"/> </LinearLayout> </linea Rlayout>

The main code is as follows, I'll add the annotations to the code, because it's the code for the entire module, so there are other features in it:

Package com.millionideas.cm.login; 
Import Android.app.ProgressDialog; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import Android.os.Handler; 
Import android.text.Editable; 
Import Android.text.TextWatcher; 
Import Android.view.View; 
Import Android.view.ViewGroup; 
Import Android.widget.Button; 
Import Android.widget.EditText; 
Import Android.widget.ImageView; 
Import Android.widget.LinearLayout; 
Import Android.widget.TextView; 
Import COM.MILLIONIDEAS.CM.R; 
Import com.millionideas.cm.home.HomeActivity; 
Import com.millionideas.cm.main.BaseActivity; 
Import Com.millionideas.cm.tools.TimeCountUtils; 
Import Org.xutils.view.annotation.ContentView; 
Import org.xutils.view.annotation.Event; 
Import Org.xutils.view.annotation.ViewInject; 
Import Java.util.regex.Matcher; 
Import Java.util.regex.Pattern; @ContentView (r.layout.activity_login) public class Loginactivity extends baseactivity implements view.onlayoutchangelistener{//Xutils Control binding @ViewInject (R.id.iv_logiN_logo) ImageView Iv_login_logo; 
 @ViewInject (R.ID.LL_LOGIN_LOGOBG) LinearLayout LL_LOGIN_LOGOBG; 
 @ViewInject (R.id.et_login_phone) EditText Et_login_phone; 
 @ViewInject (R.id.et_login_code) EditText Et_login_code; 
 @ViewInject (r.id.ll_login_warning) LinearLayout ll_login_warning; 
 @ViewInject (r.id.tv_login_wraning) TextView tv_login_wraning; 
 @ViewInject (R.id.bt_login_getcode) Button Bt_login_getcode; 
 @ViewInject (r.id.bt_login_submit) Button bt_login_submit; 
 @ViewInject (r.id.ll_login_root) LinearLayout activityrootview;//need to operate the layout of private timecountutils timecountutils; 
 Private Matcher Phone_num; 
 Private pattern PhoneNumber; 
 Private ProgressDialog ProgressDialog; 
 Private Handler Handler; private int screenheight = 0;//screen height private int keyheight = 0; 
  The height @Override protected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate) after the software disk is bounced; ScreenHeight = This.getwindowmanager (). Getdefaultdisplay (). GetHeight (); Get screen heightDegree keyheight = screenheight/3;//bounce height for screen height 1/3 timecountutils = new Timecountutils (Loginactivity.this, 60000, 1000, 
  Bt_login_getcode)//Time tool class to implement the Countdown Progressdialog=new ProgressDialog (this);//Dialog Handler=new handler (); 
  Bt_login_submit.setclickable (FALSE);  Et_login_phone.addtextchangedlistener (New Textwatcher () {//Add text change listener for EditText, change the background color of the confirmation button based on whether there is text input @Override public void Beforetextchanged (charsequence charsequence, int i, int i1, int i2) {} @Override public void Ontextchan Ged (charsequence charsequence, int i, int i1, int i2) {} @Override public void aftertextchanged (Editable edit 
     Able) {if (!et_login_phone.gettext (). toString (). Equals ("")) {bt_login_submit.setclickable (true); 
    Bt_login_submit.setbackgroundresource (R.drawable.login_button); 
     }else {bt_login_submit.setclickable (false); 
    Bt_login_submit.setbackgroundresource (R.mipmap.login_button_gray); 
 } 
   } 
  }); //xutils Event handling @Event (ValuE = {r.id.bt_login_submit, r.id.bt_login_getcode}, type = View.OnClickListener.class) private void OnClick (view view) { Switch (View.getid ()) {Case R.ID.BT_LOGIN_SUBMIT://Confirm button event if (! 
     Checkphone (Et_login_phone). Matches ()) {//Judge mobile number format ll_login_warning.setvisibility (view.visible); 
    Tv_login_wraning.settext ("Mobile phone number format is not correct"); else if (!et_login_code.gettext (). toString (). Equals ("000")) {//Authenticode judgment, set the default value for convenience test ll_login_warning.setvisibility (V Iew. 
     VISIBLE); 
    Tv_login_wraning.settext ("Incorrect verification Code"); 
     else {//condition all satisfied, start landing ll_login_warning.setvisibility (View.gone); 
     Progressdialog.setmessage ("Login ..."); Progressdialog.show ()//Eject Load dialog box handler.postdelayed (new Runnable () {//set a 1s delay operation simulate the landing process @Override pub LIC void Run () {//login successfully shut down the dialog box, jump page, turn off this page Progressdialog.dismiss ();//cannot use hide Intent intent=new Intent (loginact 
       Ivity.this, Homeactivity.class); 
       StartActivity (Intent); 
    LoginActivity.this.finish ();  }},1000); 
   } break; Case R.id.bt_login_getcode:if (Checkphone (Et_login_phone). Matches ()) {//Cell phone number correct to get the verification code, open the Countdown ll_login_warning.set 
     Visibility (View.gone); 
     Bt_login_getcode.setbackgroundresource (R.mipmap.login_button_gray); 
    Timecountutils.start (); 
     else {ll_login_warning.setvisibility (view.visible); 
    Tv_login_wraning.settext ("Mobile phone number format is not correct"); 
  } break; } public Matcher Checkphone (EditText edittext) {//Judge mobile number format PhoneNumber = pattern. Compile ("^[1][3-8][0-9]{9}$ 
  "); 
  Phone_num = Phonenumber.matcher (Edittext.gettext (). toString ()); 
 return phone_num; 
  } @Override protected void Onresume () {super.onresume (); Activityrootview.addonlayoutchangelistener (this)//to the layout settings that need to be manipulated} @Override public void Onlayoutchange (View v, int l EFT, int top, int right, int bottom, int oldleft, int oldtop, int oldright, int oldbottom) {/* old is the left upper right lower coordinate before the change The point value, no old is changed after the left upper right sit punctuation value now think that as long as the control will ActivitY pushes up more than 1/3 screen height, think soft keyboard bounce/if (oldbottom!= 0 && Bottom!= 0 && (Oldbottom-bottom > Keyheight)) { 
   Viewgroup.layoutparams params = Iv_login_logo.getlayoutparams ();//Get layout, set the width and height of the logo after keyboard bounce params.height = 300; 
   Params.width = 300; 
   Iv_login_logo.setlayoutparams (params); 
   Linearlayout.layoutparams LP = new Linearlayout.layoutparams (Ll_login_logobg.getlayoutparams ()); 
  Lp.setmargins (0, 90, 0, 50);//Set the location of the layout containing the logo ll_login_logobg.setlayoutparams (LP); else if (oldbottom!= 0 && Bottom!= 0 && (Bottom-oldbottom > Keyheight)) {//keyboard retracted, logo restored to its original size, same position 
   To the initial position viewgroup.layoutparams params = Iv_login_logo.getlayoutparams (); 
   Params.height = 480; 
   Params.width = 480; 
   Iv_login_logo.setlayoutparams (params); 
   Linearlayout.layoutparams LP = new Linearlayout.layoutparams (Ll_login_logobg.getlayoutparams ()); 
   Lp.setmargins (0, 270, 0, 150); 
  LL_LOGIN_LOGOBG.SETLAYOUTPARAMS (LP);  } 
 } 
}

The above is a small series to introduce the Android landing page logo with the keyboard retractable dynamic (perfect solution to the problem of keyboard pop-up occlusion control), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.