Creates a new builder for Alert Dialog's that supports the Material Shape system.

PiperOrigin-RevId: 223985990
This commit is contained in:
ldjesper 2018-12-04 11:56:59 -05:00 committed by ldjcmu
parent 7a69df4abf
commit bca2bd0e00
7 changed files with 522 additions and 17 deletions

View File

@ -21,6 +21,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
@ -48,21 +49,31 @@ public class DialogMainDemoFragment extends DemoFragment {
String neutralText = getResources().getString(R.string.neutral);
String title = getResources().getString(R.string.title);
String message = getResources().getString(R.string.message);
String longMessage = getResources().getString(R.string.long_message);
// message, 2 actions
addDialogLauncher(
dialogLaunchersLayout,
R.string.message_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setMessage(message)
.setPositiveButton(positiveText, null)
.setNegativeButton(negativeText, null));
// long message, 2 actions
addDialogLauncher(
dialogLaunchersLayout,
R.string.long_message_2_actions,
new MaterialAlertDialogBuilder(getContext())
.setMessage(longMessage)
.setPositiveButton(positiveText, null)
.setNegativeButton(negativeText, null));
// title, 2 actions
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setPositiveButton(positiveText, null)
.setNeutralButton(neutralText, null));
@ -71,7 +82,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_message_3_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setMessage(message)
.setPositiveButton(positiveText, null)
@ -82,7 +93,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_message_3_long_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setMessage(message)
.setPositiveButton(getResources().getString(R.string.long_positive), null)
@ -93,7 +104,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.long_title_message_too_long_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(getResources().getString(R.string.long_title))
.setMessage(message)
.setPositiveButton(getResources().getString(R.string.too_long_positive), null)
@ -104,7 +115,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.icon_title_message_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setMessage(message)
.setPositiveButton(positiveText, null)
@ -115,7 +126,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_choices_as_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setNeutralButton(neutralText, null)
.setItems(choices, null));
@ -124,7 +135,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_checkboxes_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setPositiveButton(positiveText, null)
.setNeutralButton(neutralText, null)
@ -134,7 +145,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_radiobuttons_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setPositiveButton(positiveText, null)
.setNeutralButton(neutralText, null)
@ -144,7 +155,7 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_slider_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setPositiveButton(positiveText, null)
.setNeutralButton(neutralText, null)
@ -154,24 +165,23 @@ public class DialogMainDemoFragment extends DemoFragment {
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_scrolling_2_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setMessage(multiLineMessage.toString())
.setPositiveButton(positiveText, null)
.setNeutralButton(neutralText, null));
//scrolling view
// scrolling view
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_scrolling,
new AlertDialog.Builder(getContext())
.setMessage(multiLineMessage.toString()));
new MaterialAlertDialogBuilder(getContext()).setMessage(multiLineMessage.toString()));
// title, short buttons
addDialogLauncher(
dialogLaunchersLayout,
R.string.title_2_short_actions,
new AlertDialog.Builder(getContext())
new MaterialAlertDialogBuilder(getContext())
.setTitle(title)
.setPositiveButton(R.string.short_text_1, null)
.setNeutralButton(R.string.short_text_2, null));

View File

@ -19,6 +19,7 @@
<string name="cat_dialog_title">Dialogs</string>
<string name="cat_dialog_description">Dialogs create modals that users must interact with before performing any other actions. Dialogs should only be used for user input and notices that cannot be delayed.</string>
<string name="message_2_actions">Message, 2 Actions</string>
<string name="long_message_2_actions">Long Message, 2 Actions</string>
<string name="title_2_actions">Title, 2 Actions</string>
<string name="title_message_3_actions">Title, Message, 3 Actions</string>
<string name="title_message_3_long_actions">Title, Message, 3 Long Actions</string>
@ -36,6 +37,7 @@
<string name="negative">Decline</string>
<string name="neutral">Cancel</string>
<string name="title">Title</string>
<string name="long_message">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In justo tortor, volutpat sit amet congue eu, accumsan quis nisl. Mauris accumsan lectus ipsum, a suscipit risus dictum ac. Suspendisse nec est lorem. Ut tortor est, elementum in massa id, scelerisque condimentum nibh. Ut et fermentum dolor. Suspendisse potenti. Sed dictum vestibulum metus, ut interdum ipsum. Vestibulum scelerisque ipsum commodo malesuada suscipit. Quisque pulvinar fermentum vulputate. Duis euismod, massa sed auctor egestas, ligula enim luctus orci, ac tincidunt sem massa ac enim. In non neque finibus, posuere quam eget, venenatis enim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras ut eros imperdiet, fringilla felis eget, porttitor est. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam luctus ac nulla nec elementum. Nunc sit amet nisl hendrerit, volutpat enim ut, posuere nulla. Ut porttitor magna nisi, lacinia iaculis ex tempor et. Pellentesque rhoncus augue quis pretium aliquam. Integer ut augue vitae lectus suscipit gravida. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla bibendum ex a nunc porta, vitae maximus nisl viverra. Vivamus sit amet risus varius, fringilla turpis nec, maximus elit. Cras id massa pharetra, viverra urna ac.</string>
<string name="message">Message</string>
<string name="short_text_1">1</string>
<string name="short_text_2">2</string>

View File

@ -0,0 +1,68 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.dialog;
import com.google.android.material.R;
import android.graphics.RectF;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.support.annotation.Px;
import android.support.v7.app.AlertDialog;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
/**
* Ensures that touches within the transparent region of the inset drawable used for Dialogs
* are processed as touches outside the Dialog.
*/
class InsetDialogOnTouchListener implements OnTouchListener {
private final AlertDialog dialog;
private final int leftInset;
private final int topInset;
InsetDialogOnTouchListener(AlertDialog dialog, @Px int leftInset, @Px int topInset) {
this.dialog = dialog;
this.leftInset = leftInset;
this.topInset = topInset;
}
@Override
public boolean onTouch(View view, MotionEvent event) {
View insetView = view.findViewById(R.id.parentPanel);
int insetLeft = leftInset + insetView.getLeft();
int insetRight = insetLeft + insetView.getWidth();
int insetTop = topInset + insetView.getTop();
int insetBottom = insetTop + insetView.getHeight();
RectF dialogWindow = new RectF(insetLeft, insetTop, insetRight, insetBottom);
if (dialogWindow.contains(event.getX(), event.getY())) {
return false;
}
MotionEvent outsideEvent = MotionEvent.obtain(event);
outsideEvent.setAction(MotionEvent.ACTION_OUTSIDE);
// Window.shouldCloseOnTouch does not respect MotionEvent.ACTION_OUTSIDE until Pie
view.performClick();
if (VERSION.SDK_INT >= VERSION_CODES.P) {
return dialog.onTouchEvent(outsideEvent);
} else {
dialog.onBackPressed();
return true;
}
}
}

View File

@ -0,0 +1,384 @@
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.material.dialog;
import com.google.android.material.R;
import static com.google.android.material.internal.ThemeEnforcement.createThemedContext;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.support.annotation.ArrayRes;
import android.support.annotation.AttrRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.Px;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import com.google.android.material.internal.ThemeEnforcement;
import com.google.android.material.shape.MaterialShapeDrawable;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListAdapter;
/**
* An extension of {@link AlertDialog.Builder} for use with a Material theme (e.g.,
* Theme.MaterialComponents).
*
* <p>This Builder must be used in order for AlertDialog objects to respond to color and shape
* theming provided by Material themes.
*
* <p>The type of dialog returned is still an {@link AlertDialog}; there is no specific Material
* implementation of {@link AlertDialog}.
*/
public class MaterialAlertDialogBuilder extends AlertDialog.Builder {
private static final float DEFAULT_DIM_AMOUNT = 0.32f;
@AttrRes private static final int DEF_STYLE_ATTR = R.attr.alertDialogStyle;
@StyleRes private static final int DEF_STYLE_RES = R.style.AlertDialog_MaterialComponents;
private Drawable background;
@Px private int backgroundInsetStart;
@Px private int backgroundInsetTop;
@Px private int backgroundInsetEnd;
@Px private int backgroundInsetBottom;
public MaterialAlertDialogBuilder(Context context) {
this(context, 0);
}
public MaterialAlertDialogBuilder(Context context, int themeResId) {
super(createThemedContext(context, null, DEF_STYLE_ATTR, DEF_STYLE_RES), themeResId);
// Ensure we are using the correctly themed context rather than the context that was passed in.
context = getContext();
TypedArray attributes =
ThemeEnforcement.obtainStyledAttributes(
context, null, R.styleable.MaterialAlertDialog, DEF_STYLE_ATTR, DEF_STYLE_RES);
backgroundInsetStart =
attributes.getDimensionPixelSize(
R.styleable.MaterialAlertDialog_backgroundInsetStart,
context
.getResources()
.getDimensionPixelSize(R.dimen.mtrl_alert_dialog_background_inset_start));
backgroundInsetTop =
attributes.getDimensionPixelSize(
R.styleable.MaterialAlertDialog_backgroundInsetTop,
context
.getResources()
.getDimensionPixelSize(R.dimen.mtrl_alert_dialog_background_inset_top));
backgroundInsetEnd =
attributes.getDimensionPixelSize(
R.styleable.MaterialAlertDialog_backgroundInsetEnd,
context
.getResources()
.getDimensionPixelSize(R.dimen.mtrl_alert_dialog_background_inset_end));
backgroundInsetBottom =
attributes.getDimensionPixelSize(
R.styleable.MaterialAlertDialog_backgroundInsetBottom,
context
.getResources()
.getDimensionPixelSize(R.dimen.mtrl_alert_dialog_background_inset_bottom));
attributes.recycle();
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorSurface, typedValue, true);
int surfaceColor = typedValue.data;
MaterialShapeDrawable materialShapeDrawable =
new MaterialShapeDrawable(context, null, DEF_STYLE_ATTR, DEF_STYLE_RES);
materialShapeDrawable.setFillColor(ColorStateList.valueOf(surfaceColor));
background = materialShapeDrawable;
}
@Override
public AlertDialog create() {
AlertDialog alertDialog = super.create();
Window window = alertDialog.getWindow();
/* {@link Window#getDecorView()} should be called before any changes are made to the Window
* as it locks in attributes and affects layout. */
View decorView = window.getDecorView();
window.setDimAmount(DEFAULT_DIM_AMOUNT);
int backgroundInsetLeft;
int backgroundInsetRight;
if (ViewCompat.getLayoutDirection(decorView) == ViewCompat.LAYOUT_DIRECTION_LTR) {
backgroundInsetLeft = backgroundInsetStart;
backgroundInsetRight = backgroundInsetEnd;
} else {
backgroundInsetLeft = backgroundInsetEnd;
backgroundInsetRight = backgroundInsetStart;
}
Drawable insetDrawable =
new InsetDrawable(
background,
backgroundInsetLeft,
backgroundInsetTop,
backgroundInsetRight,
backgroundInsetBottom);
window.setBackgroundDrawable(insetDrawable);
decorView.setOnTouchListener(
new InsetDialogOnTouchListener(
alertDialog, backgroundInsetLeft, backgroundInsetTop));
return alertDialog;
}
public Drawable getBackground() {
return background;
}
public MaterialAlertDialogBuilder setBackground(Drawable background) {
this.background = background;
return this;
}
public MaterialAlertDialogBuilder setBackgroundInsetStart(@Px int backgroundInsetStart) {
this.backgroundInsetStart = backgroundInsetStart;
return this;
}
public MaterialAlertDialogBuilder setBackgroundInsetTop(@Px int backgroundInsetTop) {
this.backgroundInsetTop = backgroundInsetTop;
return this;
}
public MaterialAlertDialogBuilder setBackgroundInsetEnd(@Px int backgroundInsetEnd) {
this.backgroundInsetEnd = backgroundInsetEnd;
return this;
}
public MaterialAlertDialogBuilder setBackgroundInsetBottom(@Px int backgroundInsetBottom) {
this.backgroundInsetBottom = backgroundInsetBottom;
return this;
}
// The following methods are all pass-through methods used to specify the return type for the
// builder chain.
@Override
public MaterialAlertDialogBuilder setTitle(@StringRes int titleId) {
return (MaterialAlertDialogBuilder) super.setTitle(titleId);
}
@Override
public MaterialAlertDialogBuilder setTitle(@Nullable CharSequence title) {
return (MaterialAlertDialogBuilder) super.setTitle(title);
}
@Override
public MaterialAlertDialogBuilder setCustomTitle(@Nullable View customTitleView) {
return (MaterialAlertDialogBuilder) super.setCustomTitle(customTitleView);
}
@Override
public MaterialAlertDialogBuilder setMessage(@StringRes int messageId) {
return (MaterialAlertDialogBuilder) super.setMessage(messageId);
}
@Override
public MaterialAlertDialogBuilder setMessage(@Nullable CharSequence message) {
return (MaterialAlertDialogBuilder) super.setMessage(message);
}
@Override
public MaterialAlertDialogBuilder setIcon(@DrawableRes int iconId) {
return (MaterialAlertDialogBuilder) super.setIcon(iconId);
}
@Override
public MaterialAlertDialogBuilder setIcon(@Nullable Drawable icon) {
return (MaterialAlertDialogBuilder) super.setIcon(icon);
}
@Override
public MaterialAlertDialogBuilder setIconAttribute(@AttrRes int attrId) {
return (MaterialAlertDialogBuilder) super.setIconAttribute(attrId);
}
@Override
public MaterialAlertDialogBuilder setPositiveButton(
@StringRes int textId, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setPositiveButton(textId, listener);
}
@Override
public MaterialAlertDialogBuilder setPositiveButton(
CharSequence text, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setPositiveButton(text, listener);
}
@Override
public MaterialAlertDialogBuilder setPositiveButtonIcon(Drawable icon) {
return (MaterialAlertDialogBuilder) super.setPositiveButtonIcon(icon);
}
@Override
public MaterialAlertDialogBuilder setNegativeButton(
@StringRes int textId, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setNegativeButton(textId, listener);
}
@Override
public MaterialAlertDialogBuilder setNegativeButton(
CharSequence text, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setNegativeButton(text, listener);
}
@Override
public MaterialAlertDialogBuilder setNegativeButtonIcon(Drawable icon) {
return (MaterialAlertDialogBuilder) super.setNegativeButtonIcon(icon);
}
@Override
public MaterialAlertDialogBuilder setNeutralButton(
@StringRes int textId, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setNeutralButton(textId, listener);
}
@Override
public MaterialAlertDialogBuilder setNeutralButton(
CharSequence text, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setNeutralButton(text, listener);
}
@Override
public MaterialAlertDialogBuilder setNeutralButtonIcon(Drawable icon) {
return (MaterialAlertDialogBuilder) super.setNeutralButtonIcon(icon);
}
@Override
public MaterialAlertDialogBuilder setCancelable(boolean cancelable) {
return (MaterialAlertDialogBuilder) super.setCancelable(cancelable);
}
@Override
public MaterialAlertDialogBuilder setOnCancelListener(OnCancelListener onCancelListener) {
return (MaterialAlertDialogBuilder) super.setOnCancelListener(onCancelListener);
}
@Override
public MaterialAlertDialogBuilder setOnDismissListener(OnDismissListener onDismissListener) {
return (MaterialAlertDialogBuilder) super.setOnDismissListener(onDismissListener);
}
@Override
public MaterialAlertDialogBuilder setOnKeyListener(OnKeyListener onKeyListener) {
return (MaterialAlertDialogBuilder) super.setOnKeyListener(onKeyListener);
}
@Override
public MaterialAlertDialogBuilder setItems(
@ArrayRes int itemsId, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setItems(itemsId, listener);
}
@Override
public MaterialAlertDialogBuilder setItems(CharSequence[] items, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setItems(items, listener);
}
@Override
public MaterialAlertDialogBuilder setAdapter(
final ListAdapter adapter, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setAdapter(adapter, listener);
}
@Override
public MaterialAlertDialogBuilder setCursor(
final Cursor cursor, final OnClickListener listener, String labelColumn) {
return (MaterialAlertDialogBuilder) super.setCursor(cursor, listener, labelColumn);
}
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
@ArrayRes int itemsId, boolean[] checkedItems, final OnMultiChoiceClickListener listener) {
return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(itemsId, checkedItems, listener);
}
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
CharSequence[] items, boolean[] checkedItems, final OnMultiChoiceClickListener listener) {
return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(items, checkedItems, listener);
}
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
Cursor cursor,
String isCheckedColumn,
String labelColumn,
final OnMultiChoiceClickListener listener) {
return (MaterialAlertDialogBuilder)
super.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
}
@Override
public MaterialAlertDialogBuilder setSingleChoiceItems(
@ArrayRes int itemsId, int checkedItem, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setSingleChoiceItems(itemsId, checkedItem, listener);
}
@Override
public MaterialAlertDialogBuilder setSingleChoiceItems(
Cursor cursor, int checkedItem, String labelColumn, final OnClickListener listener) {
return (MaterialAlertDialogBuilder)
super.setSingleChoiceItems(cursor, checkedItem, labelColumn, listener);
}
@Override
public MaterialAlertDialogBuilder setSingleChoiceItems(
CharSequence[] items, int checkedItem, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setSingleChoiceItems(items, checkedItem, listener);
}
@Override
public MaterialAlertDialogBuilder setSingleChoiceItems(
ListAdapter adapter, int checkedItem, final OnClickListener listener) {
return (MaterialAlertDialogBuilder) super.setSingleChoiceItems(adapter, checkedItem, listener);
}
@Override
public MaterialAlertDialogBuilder setOnItemSelectedListener(
final AdapterView.OnItemSelectedListener listener) {
return (MaterialAlertDialogBuilder) super.setOnItemSelectedListener(listener);
}
@Override
public MaterialAlertDialogBuilder setView(int layoutResId) {
return (MaterialAlertDialogBuilder) super.setView(layoutResId);
}
@Override
public MaterialAlertDialogBuilder setView(View view) {
return (MaterialAlertDialogBuilder) super.setView(view);
}
}

View File

@ -15,11 +15,18 @@
limitations under the License.
-->
<resources>
<!-- A group of styles to control the appearance of the top panel of Alert Dialogs.
For default configurations of all 3 styles, set alertDialogTheme in your App Theme to
<!-- A group of attributes to control the appearance of Alert Dialogs.
For default configurations of all attributes, set alertDialogTheme in your App Theme to
ThemeOverlay.MaterialComponents.Dialog.Alert or
ThemeOverlay.MaterialComponents.Dialog.Alert.Centered. -->
<attr name="alertDialogTitlePanelStyle" format="reference"/>
<attr name="alertDialogTitleIconStyle" format="reference"/>
<attr name="alertDialogTitleTextStyle" format="reference"/>
<declare-styleable name="MaterialAlertDialog">
<attr name="backgroundInsetStart" format="dimension"/>
<attr name="backgroundInsetTop" format="dimension"/>
<attr name="backgroundInsetEnd" format="dimension"/>
<attr name="backgroundInsetBottom" format="dimension"/>
</declare-styleable>
</resources>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<dimen name="mtrl_alert_dialog_background_inset_start">24dp</dimen>
<dimen name="mtrl_alert_dialog_background_inset_top">80dp</dimen>
<dimen name="mtrl_alert_dialog_background_inset_end">24dp</dimen>
<dimen name="mtrl_alert_dialog_background_inset_bottom">80dp</dimen>
</resources>

View File

@ -19,6 +19,12 @@
<style name="AlertDialog.MaterialComponents" parent="AlertDialog.AppCompat">
<item name="android:layout">@layout/material_alert_dialog</item>
<item name="backgroundInsetStart">@dimen/mtrl_alert_dialog_background_inset_start</item>
<item name="backgroundInsetTop">@dimen/mtrl_alert_dialog_background_inset_top</item>
<item name="backgroundInsetEnd">@dimen/mtrl_alert_dialog_background_inset_end</item>
<item name="backgroundInsetBottom">@dimen/mtrl_alert_dialog_background_inset_bottom</item>
<item name="shapeAppearance">?attr/shapeAppearanceMediumComponent</item>
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MaterialComponents.AlertDialog</item>
</style>
<style name="Base.AlertDialog.MaterialComponents.Title.Panel" parent="android:Widget">
@ -79,4 +85,9 @@
<item name="android:textAlignment" tools:ignore="NewApi">center</item>
</style>
<style name="ShapeAppearanceOverlay.MaterialComponents.AlertDialog" parent="">
<item name="cornerSize">4dp</item>
<item name="cornerFamily">rounded</item>
</style>
</resources>