Android EditText in AlertDialog seems too wide

后端 未结 4 665
挽巷
挽巷 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:31

    You can do it like this:

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    final EditText input = new EditText(this);
    input.setSingleLine(true);
    layout.setPadding(10, 0, 10, 0);
    input.setHint("Hint");
    layout.addView(input);
    
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    

    Moreover, setSingleLine is deprecated. You should use InputStyle.

提交回复
热议问题