The first app-advanced: 1, let EditText shield soft keyboard can still blink cursor: 2, EditText of the InputType parameter type (password mode-hidden display, only allowed to enter numbers, etc.)

Source: Internet
Author: User

EditText the cursor disappears after masking the soft keyboard.

At first I had a requirement: shielded system soft keyboard

Then find and use this method:

Edit_text1.setinputtype (Inputtype.type_null); Mask Soft Keyboard Popup
Edit_text2.setinputtype (Inputtype.type_null); Mask Soft Keyboard Popup
Edit_text3.setinputtype (Inputtype.type_null); Mask Soft Keyboard Popup

Let three edittext all succeed without a soft keyboard pop-up.

Later I want to set the display cursor on the edittext:

Android:textcursordrawable= "@null"
Android:cursorvisible= "true"

But there is always no cursor flashing.

----> then found this method on the Internet---->

// Mask Soft Keyboard Popup--the cursor will still blink         Hidesoftinputmethod (EDIT_TEXT1);       Hidesoftinputmethod (EDIT_TEXT2);       Hidesoftinputmethod (EDIT_TEXT3);

--the Real method here

/**= = = Hide System keyboard ======*/    //using this method to shut down the system keyboard will not appear the cursor disappears .     Public voidHidesoftinputmethod (EditText ed) {GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_        Always_hidden); String MethodName=NULL; intCurrentVersion =Android.os.Build.VERSION.SDK_INT; if(CurrentVersion >= 16){            //4.2MethodName = "Setshowsoftinputonfocus";//}Else if(CurrentVersion >= 14){            //4.0MethodName = "Setsoftinputshownonfocus"; }        if(MethodName = =NULL){            //The lowest level of the worst way, this way will give the cursor to blockEd.setinputtype (inputtype.type_null); }Else{Class<EditText> cls = EditText.class;            Method Setshowsoftinputonfocus; Try{Setshowsoftinputonfocus= Cls.getmethod (MethodName,Boolean.class); Setshowsoftinputonfocus.setaccessible (true); Setshowsoftinputonfocus.invoke (Ed,false); } Catch(Exception e) {e.printstacktrace (); }        }    }
InputType parameter types for EditText

Edit_text2.setinputtype (Inputtype.type_class_number);
Edit_text3.setinputtype (Inputtype.type_class_number);
Button bn = New button (this);
Bn.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {EditText edit_text1=(EditText) Findviewbyid (R.ID.EDIT_TEXT1); EditText edit_text2=(EditText) Findviewbyid (R.ID.EDIT_TEXT2); EditText Edit_text3=(EditText) Findviewbyid (R.ID.EDIT_TEXT3); Button b=(Button) Findviewbyid (V.getid ()); //Judging the focus (whether you have the focus) = = five-Star praise//Check what you typed (qualified)//appends the typed content to the EditText that has the focus//                    if(edit_text1.isfocused ()) {Try{Long.parselong (B.gettext (). toString (),16);//Check to see if it can be converted to 16, that is, check whether the input is a hexadecimal numberEdit_text1.append (B.gettext ());//content AppendEdit_text1.seterror (NULL);//Clear the error message box}Catch(Exception e) {edit_text1.seterror ("Please enter the hexadecimal number within the 0~~f."); }                    }Else if(edit_text2.isfocused ()) {Edit_text2.append (B.gettext ()); Edit_text2.seterror (NULL); } Else if(edit_text3.isfocused ()) {Edit_text3.append (B.gettext ()); Edit_text3.seterror (NULL); }                }            });

This can be defined in XML:

Android:inputtype parameter type description android:inputtype= "None"--Enter normal character android:inputtype= "text"--Enter ordinary character android:inputtype= " Textcapcharacters "--Enter ordinary characters android:inputtype=" textcapwords "--the first letter size android:inputtype=" textcapsentences "-- Only the first letter size android:inputtype= "Textautocorrect"--the first two AutoComplete android:inputtype= "Textautocomplete"--the first two auto-complete android: Inputtype= "Textmultiline"-Multi-line input android:inputtype= "textimemultiline"-Input method multiple lines (not necessarily supported) android:inputtype= " Textnosuggestions "--Do not prompt android:inputtype=" Texturi "--uri format android:inputtype=" textemailaddress "--Email address format Android : inputtype= "Textemailsubject"--Message subject format android:inputtype= "Textshortmessage"--Short message Format android:inputtype= " Textlongmessage "--long message format android:inputtype=" Textpersonname "--person name format android:inputtype=" Textpostaladdress "-- Postal format android:inputtype= "Textpassword"--Password format android:inputtype= "Textvisiblepassword"--Password visible format android:inputtype= " Textwebedittext "--text format as a Web Form android:inputtype=" TextFilter "--Text filter format android:inputtype=" Textphonetic "-- Pinyin input Format android:inputtype= "number"--Digital format android:inputtype= "NumberSIgned "--Signed number format android:inputtype=" Numberdecimal "--can be a floating point format with decimal point android:inputtype=" Phone "--dial keypad android:inputtype= "DateTime" android:inputtype= "date"--date keyboard android:inputtype= "Time"--temporal keyboard

First app-Advanced: 1, let EditText shield soft keyboard can still blink cursor: 2, EditText inputtype parameter type (password mode-hide display, only allow input numbers, etc.)

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.