Android Development using the Imeoptions property to change the keyboard return to the search function keys "Improve user input experience"

Source: Internet
Author: User

Keyboard input in Android is the most common and direct means of user input interaction, and there are a few things that can improve the user experience with regard to keyboard input.

First: Pop up the keyboard to move up the whole page, so that the keyboard does not obscure the control, you need to set the Windowsoftinputmode property of the activity in Androidmanifest

Statevisible

Set to this property, you can summon the soft keyboard, even if there is no input box on the interface can be forced to summon out

Adjustresize

This property indicates that the activity's main window is always resized to ensure that the soft keyboard displays space.

The effect is as follows:


<Activity    Android: Name=". Activity. Loginactivity "    Android: windowsoftinputmode="Statevisible|adjustresize"    Android: label="@string/title_activity_login"    Android: screenorientation="Portrait"></Activity>
Second: When there are multiple input controls on the page, the input control focus switch requires the user to click on the control switch, the experience is not very good, you can change the keyboard return to the "next" button, directly switch the cursor focus to the next input control. Set in the layout file

Android : imeoptions= "Actionnext" Android : singleline= "true"
can be

As shown


Third: When submitting the form, you can click the Submit button to submit, or the last edittext to get the focus when the key to set the keyboard return to send keys, so click on the keyboard key to automatically handle the logic of the submission form.

setting is also simple, the input control layout file adds two properties as follows:

Android : imeoptions= "Actionsend" Android : singleline= "true"
The logic for handling the response is detected in activity when the keyboard return is pressed

Mpassword.Setonkeylistener (NewView.onkeylistener() {@Override    Public BooleanOnKey (Viewv,intKeyCode,KeyEventEvent) {if(KeyCode== KeyEvent.Keycode_enter) {            ((Inputmethodmanager) Getsystemservice (Input_method_service)).Hidesoftinputfromwindow (loginactivity. This.Getcurrentfocus ().Getwindowtoken (),Inputmethodmanager.hide_not_always);if(Textutil.IsEmpty(Mpassword.GetText ().ToString ())) {Toastutil.getinstance().Show"Please enter your password"); }Else{Login (Musername.GetText ().ToString (),Mpassword.GetText ().ToString ()); }        }return False; }});
As shown in the following:


Four: Change the ENTER key to search button, layout file EditText Add the following two properties:

Android : singleline= "true" Android : imeoptions= "Actionsearch"
the hit check on the ENTER key is the same as the top

The example diagram is as follows:



Android Development using the Imeoptions property to change the keyboard return to the search function keys "Improve user input experience"

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.