Android settings input box and soft keyboard dynamic hover

Source: Internet
Author: User

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Tools:context= "Com.liuzheng.admin.myhidden.MainActivity">7 8     <LinearLayout9         Android:layout_width= "Match_parent"Ten Android:layout_height= "45DP" One Android:layout_alignparentbottom= "true" A android:orientation= "Horizontal"> -  -         <Button the             Android:id= "@+id/butt1" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:focusable= "true" + Android:focusableintouchmode= "true" - Android:text= "Display" /> +  A         <Button at             Android:id= "@+id/butt2" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:text= "hidden" /> -  -         <EditText in             Android:id= "@+id/edit_text" - Android:layout_width= "200DP" to Android:layout_height= "Wrap_content" /> +  -     </LinearLayout> the  * </Relativelayout>

1  Public classMainactivityextendsappcompatactivity {2 3     PrivateButton butt1;4     PrivateButton butt2;5     PrivateEditText Edit;6 7 @Override8     protected voidonCreate (Bundle savedinstancestate) {9         Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.activity_main); OneEdit =(EditText) Findviewbyid (r.id.edit_text); ABUTT1 =(Button) Findviewbyid (R.ID.BUTT1); -Butt1.setonclicklistener (NewView.onclicklistener () { - @Override the              Public voidOnClick (view view) { -                 //bind soft keyboard to EditText -Edit.setfocusable (true); -Edit.setfocusableintouchmode (true); + Edit.requestfocus (); -Inputmethodmanager InputManager =(Inputmethodmanager) Edit.getcontext (). Getsystemservice (Context.input_method_service); +Inputmanager.showsoftinput (Edit, 0); A             } at         }); -BUTT2 =(Button) Findviewbyid (R.ID.BUTT2); -Butt2.setonclicklistener (NewView.onclicklistener () { - @Override -              Public voidOnClick (view view) { - //Remove soft Keyboard display in Edit.clearfocus (); -Inputmethodmanager IMM =(Inputmethodmanager) Getsystemservice (context.input_method_service); toImm.hidesoftinputfromwindow (Edit.getwindowtoken (), 0); +             } -         }); the     } *}
1<?xml version= "1.0" encoding= "Utf-8"?>2<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"3      Package= "Com.liuzheng.admin.myhidden" >4 5<Application6Android:allowbackup= "true"7android:icon= "@mipmap/ic_launcher"8Android:label= "@string/app_name"9Android:supportsrtl= "true"TenAndroid:theme= "@style/apptheme" > One<activity android:name= ". Mainactivity " AAndroid:windowsoftinputmode= "Adjustresize" > -<intent-filter> -<action android:name= "Android.intent.action.MAIN"/> the  -<category android:name= "Android.intent.category.LAUNCHER"/> -</intent-filter> -</activity> +</application> -  +</manifest>

In the project's Androidmanifest.xml file interface corresponding to the <activity> added

Android:windowsoftinputmode= "Adjustresize"

Meaning of each value: "A" stateunspecified: The state of the soft keyboard is not specified, the system will select an appropriate state or a theme-dependent setting of "B" stateunchanged: When this activity appears, The soft keyboard will remain in the state of the previous activity, whether it is hiding or showing "C" Statehidden: When the user chooses activity, the soft keyboard is always hidden "D" Statealwayshidden: When the Activity main window gets focus , the soft keyboard is always hidden "E" statevisible: Soft keyboard is usually visible "F" statealwaysvisible: When the user chooses activity, the soft keyboard always displays the status "G" adjustunspecified: Default setting, It is usually up to the system to hide or display the "H" adjustresize: The activity always resizes the screen to allow space for the soft keyboard "I" Adjustpan: The contents of the current window will automatically move so that the current focus is never covered by the keyboard and the user can always see the part of the input

  



Android settings input box and soft keyboard dynamic hover

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.