How to Make an Alert Dialog Fill 90% of Screen Size

Can you make an alert dialog take 100% of the width on screen?

Try Below code

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);

or add custom theme in your style.xml

 <style name="DialogTheme" parent="android:Theme.Dialog">

<item name="android:layout_width">match_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>

while inflating your dialogue set this theme

dialog = new Dialog(this, R.style.DialogTheme);

How to control the width and height of the default Alert Dialog in Android?

Only a slight change in Sat Code, set the layout after show() method of AlertDialog.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.

Or you can do it in my way.

alertDialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

lp.copyFrom(alertDialog.getWindow().getAttributes());
lp.width = 150;
lp.height = 500;
lp.x=-170;
lp.y=100;
alertDialog.getWindow().setAttributes(lp);

Adjusting size of custom dialog box in android

I'm not sure if this will work for your situation, but if you want to set it to full width or something similar, you need to get the current Window for the activity and set it's layout params like so:

myDialog.show();
Window window = myDialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

Edit

FILL_PARENT has been deprecated, use instead

window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);


Related Topics



Leave a reply



Submit