How to add two edit text fields in an alert dialog

后端 未结 8 988
野趣味
野趣味 2020-12-07 16:28

I am trying to use an alert dialog to prompt for a username and a password in android. I have found this code here:

  if (token.equals(\"Not Found\"))
    {
         


        
8条回答
  •  执笔经年
    2020-12-07 16:57

    Have a look at the AlertDialog docs. As it states, to add a custom view to your alert dialog you need to find the frameLayout and add your view to that like so:

    FrameLayout fl = (FrameLayout) findViewById(android.R.id.custom);
    fl.addView(myView, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    

    Most likely you are going to want to create a layout xml file for your view, and inflate it:

    LayoutInflater inflater = getLayoutInflater();
    View twoEdits = inflater.inflate(R.layout.my_layout, f1, false);
    

提交回复
热议问题