Android Andros Disable the system input method, customize the soft keyboard, solve the EditText cursor problem demo

Source: Internet
Author: User

At present, a lot of input methods have automatic prompt completion function, in some application scenarios do not apply, need to disable the system input method, custom soft keyboard, edittext the cursor problem is more headache, online saying a lot, however, most of them can not solve the problem. The following is a demo I do for users reference.

Directly on the code:

XML Soft Keyboard:

        <android.inputmethodservice.KeyboardView             android:id= "@+id/keyboard_view"              android:layout_width= "Fill_parent"              android:layout_height= "Wrap_content"              android:background= "@color/white"              android:focusable= "true"              android:focusableintouchmode= "true"              android:keybackground= "@drawable/btn_keyboard_key"              android:keytextcolor= "@color/black"           &Nbsp;  android:visibility= "Gone"  /> 

Disable the system input method, solve the EditText cursor problem important code:

Public boolean ontouch (view v, motionevent event) {//Hide IME, display cursor edittext et= ( EditText) V;int intype = et.getinputtype (); // back up the input  typeif  (sdkint>=11)  {Class<EditText> cls=EditText.class;try {Method  Setshowsoftinputonfocus=cls.getmethod ("Setshowsoftinputonfocus",  boolean.class); Setshowsoftinputonfocus.setaccessible (false); Setshowsoftinputonfocus.invoke (Et, false);}  catch  (nosuchmethodexception e)  {e.printstacktrace ();}  catch  (illegalargumentexception e)  {e.printstacktrace ();}  catch  (illegalaccessexception e)  {e.printstacktrace ();}  catch  (invocationtargetexception e)  {e.printstacktrace ();}} Else {et.setinputtype (Android.text.InputType.TYPE_NULL); // disable soft  Inputet.setinputtype (Intype);} Keyboardutil=null;keyboardutil = new keyboardutil (Act, ctx, et); Et.ontouchevent (event);// call native handler// restore input  typekeyboardutil.showkeyboard (); return true;}

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/79/FF/wKiom1agVz-SD7VTAAHFHD1np5c676.png "title=" 648282831665697547.png "alt=" Wkiom1agvz-sd7vtaahfhd1np5c676.png "/>

Other code is not affixed, need to complete the demo, please download it yourself.

This article is from the "11010803" blog, please be sure to keep this source http://11020803.blog.51cto.com/11010803/1737081

Android Andros Disable the system input method, customize the soft keyboard, solve the EditText cursor problem demo

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.