The EditText in Android custom dialog cannot pop up the keyboard.

Source: Internet
Author: User

The EditText in Android custom dialog cannot pop up the keyboard.

Recently, my independently developed project "Medical Doctor meeting" is in beta testing and will soon be deployed in various application markets. It is a pity that the previous projects have not been shelved for some reasons. So recently I have been in a very good mood.
Today, we are working on a new project, an APP designed for lawyers and customers. There is a need for a custom dialog box. This knowledge point is actually very simple, it is the result:

However, after I finished writing it leisurely, I found that the embedded EditText in the Custom dialog box could not get the focus, and the soft keyboard could not pop up. It was depressing. When no EditText exists in the previously developed software, everything would work normally, no hidden pitfalls were found. Is a custom dialog box I wrote earlier:

Here we will solve this problem:
1. layout file of the dialog box:


  
      
           
                
                 
                 
                 
                 
             
            
        
   
  

2. Custom dialog code

// Pop up custom dialog LayoutInflater inflater = LayoutInflater. from (OnlineActivity. this); View view = inflater. inflate (R. layout. hl_law_dialog, null); // Dialog box final dialog Dialog = new Dialog (OnlineActivity. this); dialog. getWindow (). setBackgroundDrawable (new ColorDrawable (0); dialog. requestWindowFeature (Window. FEATURE_NO_TITLE); dialog. show (); // set the screen width to WindowManager windowManager = getWindowManager (); Display display Display = windowManager. getdefadisplay display (); WindowManager. layoutParams lp = dialog. getWindow (). getAttributes (); lp. width = (int) (display. getWidth (); // you can specify the dialog width. getWindow (). setAttributes (lp); dialog. getWindow (). setContentView (view); final EditText et_obj = (EditText) view. findViewById (R. id. et_obj); // The final EditText et_name = (EditText) view. findViewById (R. id. et_name); // name: final EditText et_phone = (EditText) view. findViewById (R. id. et_phone); // call TextView TV _go = (TextView) view. findViewById (R. id. TV _go); // confirm the delegate final ImageView iv_close = (ImageView) view. findViewById (R. id. iv_close); // confirm the delegate

The above is the correct method, so where is my mistake?
My previous statement was:

// Dialog box final dialog Dialog = new AlertDialog. builder (OnlineActivity. this ). create (); dialog. getWindow (). setBackgroundDrawable (new ColorDrawable (0); dialog. requestWindowFeature (Window. FEATURE_NO_TITLE); dialog. show ();

Therefore, you only need to replace AlertDialog with Dialog to solve this problem.

Imagine:
1. What is the effect if this code is not added?

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);


The title bar appears ugly.

2. What is the effect if this code is not added?

WindowManager windowManager = getWindowManager (); Display display = windowManager. getdefadisplay display (); WindowManager. layoutParams lp = dialog. getWindow (). getAttributes (); lp. width = (int) (display. getWidth (); // you can specify the dialog width. getWindow (). setAttributes (lp );


The dialog box is so narrow.

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.