I was trying to get the width of an AlertDialog in Pixels and also set its width dynamically.
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);
The above code didn't work for me. Also, I followed other codes too like here but none helped.
How can I get and set width of AlertDialog in pixels or dp?