indira
indira

Reputation: 6687

Resize Edit box inside Alert dialog in Android

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();   

Upvotes: 1

Views: 2165

Answers (2)

Chirag
Chirag

Reputation: 56925

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 .

Upvotes: 3

Venky
Venky

Reputation: 11107

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.....

Upvotes: -1

Related Questions