Problems encountered during the use of Android EditText

Source: Internet
Author: User

    • At first editetext the focus waits for input and the cursor flashes.

WORKAROUND: You need to have the parent control get the focus.

Android:focusable= "true" android:focusableintouchmode= "true"
    • Remove the default border, below 4.0 is the line below the EditText.

Workaround: This is because of the background of the edittext, so only need to replace its background.

Android:background= "@null"
    • After you set the default display of the prompt message (for example, enter a keyword above), the message will not disappear immediately, to the input text and text displayed in the input box when the message will disappear.

Workaround: Do the processing when the Editetext focus changes.

 Msearchtext.setonfocuschangelistener (new   Onfocuschangelistener () {@Override  public  void  Onfocuschange (View V,  Boolean   Hasfocus) { // 
   
     TODO auto-generated Method stub  
    if  
     (Hasfocus) {((EditText) v). Sethint ( "" 
     else   {((EditText) v). Sethin                T ( Please enter the keyword "); }            }                    }); 
    • When you click the Search button, you should let EditText lose focus and hide the IME.

WORKAROUND: Set the click Listener for the Search button, listen to the user click the Search button to get the focus of the search button, and then get the input method manager to hide the input method.

View.findviewbyid (R.ID.MENU_SEARCH_BT). Setonclicklistener ( This);
     @Override Public voidOnClick (View v) {//TODO auto-generated Method Stub if(V.getid () = =R.ID.MENU_SEARCH_BT) { //Search KeywordsGetFocus (V.getrootview ()); } } Private voidGetFocus (View v) {v.setfocusable (true); V.setfocusableintouchmode (true); V.requestfocus (); Inputmethodmanager IMM= (Inputmethodmanager) This. Getactivity (). Getsystemservice (Context.input_method_service); if(Imm.isactive ()) {Imm.hidesoftinputfromwindow (Getactivity (). Getcurrentfocus (). Getwind Owtoken (),0); } }

Problems encountered during the use of Android EditText

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.