Dialog设置自定义高度

 String items[] = new String[]{"菜单1","菜单2","菜单3","菜单4"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(
                "菜单").setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //自己实现的内容
                dialog.dismiss();
            }


        });
        AlertDialog ab = builder.create();
        ab.show();
        WindowManager manager = getWindowManager();
        Display d = manager.getDefaultDisplay();
        Window window = ab.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.height = (int) (d.getHeight() * 0.5);
        params.gravity = Gravity.CENTER_HORIZONTAL;
        ab.getWindow().setAttributes(params);

你可能感兴趣的:(Dialog设置自定义高度)