警报对话框间距问题与textview和编辑文本

m4n*_*n07 3 android textview android-edittext android-alertdialog

我无法在AlertDialog中看到"我的数据",因为它与EditText重叠.

           Context context = MyActivity.this;
           AlertDialog.Builder alert = new AlertDialog.Builder(context);

            alert.setTitle(" NEW TITLE");
            alert.setMessage("MESSAGE 1");

            final TextView tx = new TextView(this);
            tx.setText("MY DATA");
            alert.setView(tx);

            // Set an EditText view to get user input   
              final EditText input = new EditText(this); 
              alert.setView(input);


            alert.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                }
            });

            alert.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked Cancel so do some stuff */
                }
            });

            alert.create();
            alert.show();
Run Code Online (Sandbox Code Playgroud)

mud*_*dit 5

试试这个:

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(Vertical);

            final TextView tx = new TextView(this);
            tx.setText("MY DATA");
            layout.addView(tx);

            // Set an EditText view to get user input   
              final EditText input = new EditText(this); 
              layout.addView(input);

 alert.setView(layout);
Run Code Online (Sandbox Code Playgroud)