1

I would like to create an AlertDialog similar to this figure. I can't resize the EditText view. How do I resize it?

enter image description here

alert = new AlertDialog.Builder(this);
alert.setTitle("Enter Destination");
alert.setIcon(R.drawable.icon);

final EditText editAddress = new EditText(this);
editAddress.setLayoutParams(new LayoutParams(200, 20)); 
alert.setView(editAddress);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
    }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
    }
});

alert.show();   
Brad
  • 9,113
  • 10
  • 44
  • 68
indira
  • 6,569
  • 18
  • 65
  • 80

2 Answers2

3

Here i add one function that will open a dialog.

 public void openDialog()
 {
     LinearLayout linearLayout = new LinearLayout(this);
     linearLayout.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));
     linearLayout.setPadding(30, 0, 30, 0);

    final EditText saveas = new EditText(this);
    saveas.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));
    saveas.setImeOptions(EditorInfo.IME_ACTION_DONE);
    saveas.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    saveas.setHint("Folder");
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("Rename Folder");
    dialog.setMessage("Rename Folder");

    linearLayout.addView(saveas);

    dialog.setView(linearLayout);

    dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface dialoginterface, int buttons) 
        {

        }
    });

    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface arg0, int buttons) 
        {
        }
    });
    dialog.show();
 }

please change linear layout padding as per your rwquirement .

Chirag
  • 56,621
  • 29
  • 151
  • 198
-1

Instead of creating Alert Dialog you can Inflate a view and keep on Edit text box of your own height and width and two button ok,cancel..

check this for inflating a view Inflate View.....

Community
  • 1
  • 1
Venky
  • 11,049
  • 5
  • 49
  • 66