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
How to Change the Floating Label Color of Textinputlayout
How to Change Position of Toast in Android
How to Disable an Android Button
How to Make Surfaceview Transparent
Runtimeexception: Unable to Instantiate Application
How to Start Activity in Another Application
How to Sign an Android APK File
No Resource Found That Matches the Given Name '@Style/Theme.Appcompat.Light'
Inject CSS to a Site with Webview in Android
Android Chrome Ignoring -Webkit-Text-Size-Adjust:None Property. Text Is Being Scaled When Zoomed Out
Generate Sha-1 for Flutter/React-Native/Android-Native App
Android Update Activity UI from Service
Android Writing Logs to Text File
Error Type 3 Error: Activity Class {} Does Not Exist
Android: Unable to Add Window. Permission Denied for This Window Type
Android: Java.Lang.Securityexception: Permission Denial: Start Intent
Eclipse Giving Error, Missing R.Java File After Recent Update