Android--edittext Automatic Popup Input Method

Source: Internet
Author: User

First, open the Input Method window

1.EditText start activity when the software keyboard XML file is configured in the popup

Manifest the corresponding activity of the configuration, will EditText set the property Android:windowsoftinputmode=statevisible, when entering this page, the default Pop-up IME.

<android:name= ". Ui.login"  android:configchanges= "orientation| Keyboardhidden|locale "  android:screenorientation=" Portrait "  android: Windowsoftinputmode= "Statevisible|adjustpan"></activity >

2. Set the Windowsoftinputmode property in XML to Adjustunspecified|statehidden

3.

    1. EditText titleinput = (EditText) Findviewbyid (r.id.create_edit_title);
    2. Titleinput.setfocusable (true);
    3. Titleinput.requestfocus ();
    4. Onfocuschange (titleinput.isfocused ());

Whether

Final BooleanIsfocus =Hasfocus;
(NewHandler ()). Postdelayed (NewRunnable () { Public voidrun () { Inputmethodmanager imm=(inputmethodmanager) Titleinput.getcontext (). Getsystemservice       (Context.input_method_service); if(isfocus) {imm. Togglesoftinput(0, inputmethodmanager.hide_not_always); } Else{imm. Hidesoftinputfromwindow(Titleinput.getwindowtoken (),0); }
}

Second, hide the Input method window

2. Force Hidden Android IME window

EditText edit= (EditText) Findviewbyid (R.id.edit); Inputmethodmanager imm = (inputmethodmanager) getsystemservice (context.input_method_service); Imm. Hidesoftinputfromwindow (Edit.getwindowtoken (), 0);

2, EditText always does not eject the software keyboard

EditText edit= (EditText) Findviewbyid (R.id.edit); Edit. Setinputtype (Inputtype.type_null);  

① in the layout file, place an invisible linearlayout in front of the edittext, allowing him to take the lead in getting the focus:

< LinearLayout android:focusable = "true" Android:focusableintouchmode = "true" Android:layout_width = "0px" Android:layout_height = "0px" />  

Properties Android:inputtype : Specifies the type of input method,int type, which can be used to select multiple. The value can be referenced by: Android.text.InputType class. The values include:text,texturi,phone,number, etc.

Acquisition of Focus:
titleinput.setfocusable (true); Titleinput.requestfocus ();  

Cancellation of Focus:
Edit.setfocusable (false); or Edit.clearfocus ();




Four: The functions of handling soft keyboards that are often called are as follows:

1. Open the Input Method window:

    1. Inputmethodmanager Inputmethodmanager = (inputmethodmanager) getsystemservice (Context.input_method_service);
    2. Edit text or other views that accept soft keyboard input
    3. Imm.showsoftinput (submitbt,inputmethodmanager.show_forced);

2. Close the Access Law window

    1. Inputmethodmanager Inputmethodmanager = (inputmethodmanager) getsystemservice (Context.input_method_service);
    2. Inputmethodmanager.hidesoftinputfromwindow (opelistactivity. This.getcurrentfocus (). Getwindowtoken (),
    3. Inputmethodmanager.hide_not_always);
    4. Edit text or other views that accept soft keyboard input
    5. Inputmethodmanagerwww.2cto.com
    6. . Showsoftinput (submitbt,inputmethodmanager.show_forced);

3, if the input method is turned off, if not open then open

    1. Inputmethodmanager m= (Inputmethodmanager) Getsystemservice (Context.input_method_service);
    2. M.togglesoftinput (0, inputmethodmanager.hide_not_always);

4, get the input method open state

    1. Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
    2. Boolean isopen=imm.isactive ();

IsOpen returns true to indicate that the input method is open










Android--edittext Automatic Popup Input Method

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.