Skip to content

Commit

Permalink
[TimePicker] Made dialog container color configurable in xml style.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 519184711
  • Loading branch information
pekingme committed Mar 24, 2023
1 parent 500c8eb commit 5f542c8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ public int getInputMode() {
public final Dialog onCreateDialog(@Nullable Bundle bundle) {
Dialog dialog = new Dialog(requireContext(), getThemeResId());
Context context = dialog.getContext();
int surfaceColor =
MaterialAttributes.resolveOrThrow(
context, R.attr.colorSurface, MaterialTimePicker.class.getCanonicalName());

MaterialShapeDrawable background =
new MaterialShapeDrawable(
Expand All @@ -199,11 +196,12 @@ public final Dialog onCreateDialog(@Nullable Bundle bundle) {

clockIcon = a.getResourceId(R.styleable.MaterialTimePicker_clockIcon, 0);
keyboardIcon = a.getResourceId(R.styleable.MaterialTimePicker_keyboardIcon, 0);
int backgroundColor = a.getColor(R.styleable.MaterialTimePicker_backgroundTint, 0);

a.recycle();

background.initializeElevationOverlay(context);
background.setFillColor(ColorStateList.valueOf(surfaceColor));
background.setFillColor(ColorStateList.valueOf(backgroundColor));
Window window = dialog.getWindow();
window.setBackgroundDrawable(background);
window.requestFeature(Window.FEATURE_NO_TITLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

<attr name="keyboardIcon" />
<attr name="clockIcon" />
<attr name="backgroundTint" />

</declare-styleable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<item name="shapeAppearance">?shapeAppearanceMediumComponent</item>
<item name="keyboardIcon">@drawable/ic_keyboard_black_24dp</item>
<item name="clockIcon">@drawable/ic_clock_black_24dp</item>
<item name="backgroundTint">?attr/colorSurface</item>
</style>

<style name="Widget.MaterialComponents.TimePicker.Display" parent="Widget.MaterialComponents.Chip.Choice">
Expand Down Expand Up @@ -142,6 +143,7 @@

<style name="Widget.Material3.MaterialTimePicker" parent="Widget.MaterialComponents.TimePicker">
<item name="shapeAppearance">@macro/m3_comp_time_picker_container_shape</item>
<item name="backgroundTint">@macro/m3_comp_time_picker_container_color</item>
</style>

<style name="Widget.Material3.MaterialTimePicker.ImageButton" parent="Widget.MaterialComponents.TimePicker.ImageButton">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<!-- Generated from token set (md.comp.time-picker) in context (platform=android, audience=3p). -->
<!-- Enabled - Container -->
<macro name="m3_comp_time_picker_clock_dial_color">?attr/colorSurfaceVariant</macro>
<macro name="m3_comp_time_picker_container_color">?attr/colorSurface</macro>
<dimen name="m3_comp_time_picker_container_elevation">@dimen/m3_sys_elevation_level3</dimen>
<macro name="m3_comp_time_picker_container_shape">?attr/shapeAppearanceCornerExtraLarge</macro>
<macro name="m3_comp_time_picker_time_selector_selected_container_color">?attr/colorPrimaryContainer</macro>
Expand Down

0 comments on commit 5f542c8

Please sign in to comment.