How to make a edittext box in a dialog

后端 未结 8 1885
借酒劲吻你
借酒劲吻你 2020-11-28 01:34

I am trying to make a edittext box in a dialog box for entering a password. and when I am doing I am not able to do. I am a beginner in it. Please help me in this.



        
8条回答
  •  天涯浪人
    2020-11-28 01:45

    Use Activtiy Context

    Replace this

      final EditText input = new EditText(this);
    

    By

      final EditText input = new EditText(MainActivity.this);  
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,
                            LinearLayout.LayoutParams.MATCH_PARENT);
      input.setLayoutParams(lp);
      alertDialog.setView(input); // uncomment this line
    

提交回复
热议问题