Skip to content

Commit 968a7ee

Browse files
pekingmepaulfthomas
authored andcommitted
[Slider] Updates tick marks color to fix the contrast in medium / high contrast modes.
Resolves #4204 PiperOrigin-RevId: 652895433
1 parent b9a2ce9 commit 968a7ee

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

lib/java/com/google/android/material/slider/BaseSlider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ public void setTrackActiveTintList(@NonNull ColorStateList trackColor) {
17501750
}
17511751
trackColorActive = trackColor;
17521752
activeTrackPaint.setColor(getColorForState(trackColorActive));
1753-
stopIndicatorPaint.setColor(getColorForState(trackColorActive));
17541753
invalidate();
17551754
}
17561755

@@ -2838,7 +2837,7 @@ protected void drawableStateChanged() {
28382837
activeTrackPaint.setColor(getColorForState(trackColorActive));
28392838
inactiveTicksPaint.setColor(getColorForState(tickColorInactive));
28402839
activeTicksPaint.setColor(getColorForState(tickColorActive));
2841-
stopIndicatorPaint.setColor(getColorForState(trackColorActive));
2840+
stopIndicatorPaint.setColor(getColorForState(tickColorInactive));
28422841
for (TooltipDrawable label : labels) {
28432842
if (label.isStateful()) {
28442843
label.setState(getDrawableState());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2021 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
18+
<item android:color="?attr/colorOnPrimary" android:state_enabled="true"/>
19+
<!-- When disabled, the tick marks over active track should be the same color as the inactive track. -->
20+
<item android:alpha="@dimen/m3_comp_slider_disabled_inactive_track_opacity"
21+
android:color="@macro/m3_comp_slider_disabled_inactive_track_color"/>
22+
</selector>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2021 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
18+
<item android:color="?attr/colorOnSecondaryContainer" android:state_enabled="true" />
19+
<!-- When disabled, the tick marks over inactive track should be the same color as the active track. -->
20+
<item android:alpha="@dimen/m3_comp_slider_disabled_active_track_opacity"
21+
android:color="@macro/m3_comp_slider_disabled_active_track_color" />
22+
</selector>

lib/java/com/google/android/material/slider/res/values/styles.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<item name="haloColor">#00FFFFFF</item>
6262
<item name="labelStyle">@style/Widget.Material3.Slider.Label</item>
6363
<item name="thumbColor">@color/m3_slider_thumb_color</item>
64-
<item name="tickColorActive">@color/m3_slider_inactive_track_color</item>
65-
<item name="tickColorInactive">@color/m3_slider_active_track_color</item>
64+
<item name="tickColorActive">@color/m3_slider_active_tick_marks_color</item>
65+
<item name="tickColorInactive">@color/m3_slider_inactive_tick_marks_color</item>
6666
<item name="tickRadiusActive">@null</item>
6767
<item name="tickRadiusInactive">@null</item>
6868
<item name="trackColorActive">@color/m3_slider_active_track_color</item>

0 commit comments

Comments
 (0)