Custom dialog too small

后端 未结 11 2423
轻奢々
轻奢々 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:52

    Try this

    For setting dialog width and height as per device screen size

        Display display;
        int DisplayWidth, DisplayHeight, DialogWidth, DialogHeight;
        Dialog dialog;
    
    display =((WindowManager)activity_context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            DisplayWidth = display.getWidth();
            DisplayHeight = display.getHeight();
    
            if(DisplayHeight > DisplayWidth)
            {
                DialogWidth = (6 * DisplayWidth) / 7 ;
                DialogHeight = (4 * DisplayHeight) / 5 ;
            }
            else
            {
                DialogWidth = (6 * DisplayWidth) / 9 ;
                DialogHeight = (4 * DisplayHeight) / 5 ;
            }
    
            dialog = new Dialog(activity_context);
    
              // Set your dialog width and height dynamically as per your screen.
    
            Window window = dialog.getWindow();
            window.setLayout(DialogWidth,DialogHeight);
            window.setGravity(Gravity.CENTER);
    
            dialog.show();
    

提交回复
热议问题