Android EditText in AlertDialog seems too wide

后端 未结 4 748
挽巷
挽巷 2021-02-13 20:03

It seems like the EditText in the image below is too wide. I assume that I have misused the SDK in some way and until convinced otherwise I am not looking for a way to specify

4条回答
  •  温柔的废话
    2021-02-13 20:27

    Just sorted this myself. Using an instance of AlertDialog, you can specify setView and pass in spacing parameters. This will work.

    final EditText input = new EditText(this);
    
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Title");
    alertDialog.setMessage("Message");
    alertDialog.setView(input, 10, 0, 10, 0); // 10 spacing, left and right
    alertDialog.setButton("OK", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Clicked
        }
    });
    alertDialog.show();
    

    Edit: I'm aware this question is old, but no solution was provided.

提交回复
热议问题