ピクセル単位でAlertDialogの幅を取得しようとしていて、その幅を動的に設定しようとしていました。AlertDialogの幅をピクセルまたはdpで取得する
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.CENTER;
dialog.getWindow().setAttributes(lp);
上記のコードは私にとっては機能しませんでした。また、私もhereのような他のコードに従っていましたが、役に立たなかった。
AlertDialogをピクセルまたはdpで取得して設定するにはどうすればよいですか?そのカスタムダイアログは、そのルートビューを取る場合
あなたが試したコードですか? –