Custom dialog too small

后端 未结 11 2431
轻奢々
轻奢々 2020-12-10 10:53

I have an android activity that implements a custom dialog.The application is running ok but the dialog is too small,i want to display a bigger dialog.How can i achieve this

11条回答
  •  抹茶落季
    2020-12-10 11:37

    Change your dialog dimension on runtime:

    yourDialog.show();
    yourDialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);
    

    You can do that for both dimension, in my example i only changed the width. Hope it helps!

    EDIT

    I forgot to mention where i took width:

    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    

    EDIT 2

    Try this code:

    Dialog yourDialog = dialogFragment.getDialog();
    yourDialog.getWindow().setLayout((6 * width)/7, (4 * height)/5);
    

提交回复
热议问题