开发者

Resize Edit box inside Alert dialog in Android

开发者 https://www.devze.com 2023-02-18 11:10 出处:网络
I would like to create an AlertDialog similar to this figure. I can\'t resize the EditText view. How do I resize it?

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

Resize Edit box inside Alert dialog in Android

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.OnClickLi开发者_高级运维stener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
    }
});

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

alert.show();   


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 .


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

0

精彩评论

暂无评论...
验证码 换一张
取 消