Skip to content

Commit

Permalink
[DatePicker] Made dialog container color configurable in xml style.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 520113790
  • Loading branch information
pekingme committed Mar 29, 2023
1 parent 62aa802 commit 7b2c19b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Expand Up @@ -230,17 +230,26 @@ public final Dialog onCreateDialog(@Nullable Bundle bundle) {
Dialog dialog = new Dialog(requireContext(), getThemeResId(requireContext()));
Context context = dialog.getContext();
fullscreen = isFullscreen(context);
int surfaceColor =
MaterialAttributes.resolveOrThrow(
context, R.attr.colorSurface, MaterialDatePicker.class.getCanonicalName());
background =
new MaterialShapeDrawable(
context,
null,
R.attr.materialCalendarStyle,
R.style.Widget_MaterialComponents_MaterialCalendar);

TypedArray a =
context.obtainStyledAttributes(
null,
R.styleable.MaterialCalendar,
R.attr.materialCalendarStyle,
R.style.Widget_MaterialComponents_MaterialCalendar);

int backgroundColor = a.getColor(R.styleable.MaterialCalendar_backgroundTint, 0);

a.recycle();

background.initializeElevationOverlay(context);
background.setFillColor(ColorStateList.valueOf(surfaceColor));
background.setFillColor(ColorStateList.valueOf(backgroundColor));
background.setElevation(ViewCompat.getElevation(dialog.getWindow().getDecorView()));
return dialog;
}
Expand Down
Expand Up @@ -39,6 +39,7 @@

<declare-styleable name="MaterialCalendar">
<attr name="android:windowFullscreen"/>
<attr name="backgroundTint"/>
<attr name="dayStyle" format="reference"/>
<attr name="dayInvalidStyle" format="reference"/>
<attr name="daySelectedStyle" format="reference"/>
Expand Down
Expand Up @@ -31,6 +31,7 @@

<style name="Widget.MaterialComponents.MaterialCalendar" parent="android:Widget">
<item name="android:windowFullscreen">false</item>
<item name="backgroundTint">?attr/colorSurface</item>
<item name="shapeAppearance">?attr/shapeAppearanceMediumComponent</item>
<item name="dayStyle">@style/Widget.MaterialComponents.MaterialCalendar.Day</item>
<item name="dayInvalidStyle">@style/Widget.MaterialComponents.MaterialCalendar.Day.Invalid</item>
Expand Down Expand Up @@ -204,6 +205,7 @@
<!-- M3 Date Picker styles -->
<style name="Widget.Material3.MaterialCalendar" parent="Widget.MaterialComponents.MaterialCalendar">
<item name="android:windowFullscreen">false</item>
<item name="backgroundTint">@macro/m3_comp_date_picker_modal_container_color</item>
<item name="dayStyle">@style/Widget.Material3.MaterialCalendar.Day</item>
<item name="dayInvalidStyle">@style/Widget.Material3.MaterialCalendar.Day.Invalid</item>
<item name="daySelectedStyle">@style/Widget.Material3.MaterialCalendar.Day.Selected</item>
Expand Down
Expand Up @@ -21,6 +21,7 @@

<!-- Generated from token set (md.comp.date-picker.modal) in context (platform=android, audience=3p). -->
<!-- Enabled - Container -->
<macro name="m3_comp_date_picker_modal_container_color">?attr/colorSurface</macro>
<macro name="m3_comp_date_picker_modal_container_shape">?attr/shapeAppearanceCornerExtraLarge</macro>
<style name="ShapeAppearance.M3.Comp.DatePicker.Modal.Date.Container.Shape" parent="ShapeAppearance.M3.Sys.Shape.Corner.Full"/>
<macro name="m3_comp_date_picker_modal_date_today_container_outline_color">?attr/colorPrimary</macro>
Expand Down

0 comments on commit 7b2c19b

Please sign in to comment.