I want the dialog doesn't stretch to fit width of display screen. I want the dialog had about 90% of screen width and center its. How can I do it?
Thank you very much ^^
I want the dialog doesn't stretch to fit width of display screen. I want the dialog had about 90% of screen width and center its. How can I do it?
Thank you very much ^^
You can give style with below attributes to get dialog size as percentage of screen.
<style name="YourDialogTheme">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
Then Apply theme as below in your dialog:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.YourDialogTheme));
For the easiest way you can do something like this:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/defaultMargin"
android:paddingRight="@dimen/defaultMargin">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
also, this link can referred
Here is the example to set margins in dialogs
final Dialog dialog = new Dialog(context);
// ...
// e.g. top + right margins:
dialog.getWindow().setGravity(Gravity.TOP|Gravity.RIGHT);
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.x = 100; // right margin
layoutParams.y = 170; // top margin
dialog.getWindow().setAttributes(layoutParams);
// e.g. bottom + left margins:
dialog.getWindow().setGravity(Gravity.BOTTOM|Gravity.LEFT);
WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
layoutParams.x = 100; // left margin
layoutParams.y = 170; // bottom margin
dialog.getWindow().setAttributes(layoutParams);