Context
A smoothingly simple task, I want to set a height AlertDialogcontaining a custom view. After going through a dozen SO questions on this, I came up with 12! possible answers. After they tried everything (which is 15 years old when trying per second), it seems that a header on the screen has the same effect: no. The reason I want to do this is because my user view does not have intriguing dimensions, it just covers the space in which it is defined.
Goals
The question here refers to a soft goal, but I would gladly accept the answer for a difficult goal!
Soft target: Create one AlertDialogthat has a user-defined empty one ViewGroup(or containing, say, ImageView), and set the width and height of the dialog box for a specific value.
Tough goal: Create AlertDialogby displaying a square shape that makes the most of the space when the dialogs are set programmatically.
My attempts are compressible
Java:
View layout = getLayoutInflater ().inflate (R.layout.alerttest, null);
AlertDialog alert = new AlertDialog.Builder (this)
.setPositiveButton(R.string.alert_dialog_ok, null)
.setTitle ("Don't cry, will you?")
.create();
alert.show ();
FrameLayout fl = (FrameLayout) alert.findViewById (android.R.id.custom);
fl.addView (layout, new LayoutParams (500, 500));
alert.getWindow ().setLayout (800, 600);
alerttest.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="500dp"
android:layout_height="500dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</FrameLayout>
Results: . When it does not fall (for usually good reasons), only the width is set. The height is compressed.
Related Questions
Many thanks!