Android system, when you click EditText, hide the system soft keyboard, display the cursor

Source: Internet
Author: User

because the project to use a custom random keyboard, so you have to shield the system soft keyboard, but in the 4.0 test system, using the Edittext.setinputtype (Inputtype.type_null) method is able to hide the keyboard, However, the cursor is also hidden, so it cannot be used.

3.0 The following versions can be implemented with Edittext.setinputtype (Inputtype.type_null) . or set Edittext.setkeylistener (null) to implement. 3.0 or later in addition to calling the Hidden method Setshowsoftinputonfocus (false), because it is the internal method of the system, cannot be called directly, so it is called by reflection, as follows

In the project (the current project is using android4.0):

/span>

int sdk_int = android.os.build.version.sdk_int;if (sdk_int <= 10) {//click EditText, block default IME edittext.setinputtype ( Inputtype.type_null); EditText is the input text box for the declaration. } else {//click EditText, Hide System ime getwindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_ HIDDEN); try {class<edittext> cls = Edittext.class; method = Cls.getmethod ("Setshowsoftinputonfocus", boolean.class);//4.0 is Setshowsoftinputonfocus, 4.2 is setsoftinputshownonfocusmethod.setaccessible (false); Method.invoke (EditText, false); EditText is the input text box for the declaration. } catch (Nosuchmethodexception e) {e.printstacktrace ();} catch (IllegalArgumentException e) {e.printstacktrace ();} catch (Illegalaccessexception e) {e.printstacktrace ();} catch (InvocationTargetException e) {e.printstacktrace ()}}

Note:

The method of reflection above is found from the source code of TextView. Because EditText is inherited TextView, see the Internet is said to have the SDK inside is "Setsoftinputshownonfocus", anyway, specifically with their own SDK should be. 4.0 system corresponding to the set is setshowsoftinputonfocus, 4.2 system corresponding to the set is Setsoftinputshownonfocus, these two versions have been tested, is correctly available.


Reference:

Android Customizing the soft keyboard implementation

Android Customizing the soft keyboard

Android.edittext when Clicked , Hide System pop-up keyboard , display the cursor?

http://blog.163.com/[email protected]/blog/static/5550761120149684736794/


On Android, when you click EditText, hide the system soft keyboard and display the cursor

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.