我正在尝试制作自定义对话框。这是代码 -
public static void dialogPinOptions(Context context, String pin) {
con = context;
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow()
.setLayout((int) (MainActivity.width * 0.75), (int) (MainActivity.height * 0.55));
dialog.setContentView(R.layout.dialog_pin_new_user);
dialog.show();
/// rest of the code
}
我首先设置大小,然后设置内容以修复对话框的大小。
我使用以下内容来获取屏幕大小 -
// Getting dimensions of screen
if (Build.VERSION.SDK_INT == 11 || Build.VERSION.SDK_INT == 12) {
Point size = new Point();
try {
this.getWindowManager().getDefaultDisplay().getSize(size);
width = size.x;
height = size.y;
} catch (NoSuchMethodError e) {
Log.i("error", "it can't work");
}
}
else {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
}
但是我的盒子大小不正确。 Here is a picture.
左侧的模拟器具有API 14,右侧是带有API 17的平板电脑的屏幕截图。