Android Development: Turn off the soft keyboard in EditText

Source: Internet
Author: User

1. EditText has focus (focusable is true) prevents Input method pop-up

Java code
  1. edittext= (EditText) Findviewbyid (r.id.txtbody);
  2. Edittext.setontouchlistener (new Ontouchlistener () {
  3. Public Boolean OnTouch (View V, motionevent event) {
  4. Edittext.setinputtype (Inputtype.type_null); //Off soft keyboard
  5. return false;
  6. }
  7. });



2. Prevent Input Method pop-up when Eidttext no focus (Focusable=false)

Java code
    1. Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Input_method_service);
    2. Imm.hidesoftinputfromwindow (Edittext.getwindowtoken (), 0);



1. Call the display system default Input method

Method One,

Java code
    1. Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
    2. Imm.showsoftinput (M_receiverview (view) with soft keyboard input, inputmethodmanager.show_forced (provides markup for the current action, show_forced indicates force display) );




Method Two,

Java code
    1. Inputmethodmanager m= (Inputmethodmanager) Getsystemservice (Context.input_method_service);
    2. M.togglesoftinput (0, inputmethodmanager.hide_not_always); (This method can implement the input method to switch the display on the window, if the input method is already displayed on the window, then hide, if hidden, then display the input method to the window)




2. Call the hidden system default Input method

Java code
    1. ((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow (WidgetSearchActivity.   This.getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); (Widgetsearchactivity is the current activity)




3. Get the Input Method open state

Java code
    1. inputmethodmanager imm =  (Inputmethodmanager) GetSystemService ( Context.input_method_service);   
    2. boolean isopen=imm.isactive ();   
    3. isopen if return true, the Input method opens   





Original: http://sunxin1001.iteye.com/blog/854182
http://getcn.net/index.php?mod=skill&action=detail&id=43978


Other than that
Parameter meaning
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
The soft keyboard covers the activity directly, which is usually the default value
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
The activity height changes, letting out the soft keyboard space. and WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN to 2 for the value of 1
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
The activity displays the Soft keyboard window directly when it is opened, if that window is needed (i.e., a edittext or ditable control)
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
When the activity is open, the Soft keyboard window is not displayed directly until the user touches the text box himself.

Android Development: Turn off the soft keyboard in EditText

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.