Skip to content

Commit 2e95296

Browse files
paulfthomaskendrickumstattd
authored andcommitted
[Slider] Add support for track icons
- added trackIconActive, trackIconActiveSize and trackIconActiveColor attrs - added trackIconInactive, trackIconInactiveSize and trackIconInactiveColor attrs - added tests and demos - updated documentation PiperOrigin-RevId: 689804000
1 parent 31fa412 commit 2e95296

File tree

8 files changed

+395
-22
lines changed

8 files changed

+395
-22
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Copyright (C) 2024 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:autoMirrored="true"
20+
android:tint="#000000"
21+
android:viewportHeight="24"
22+
android:viewportWidth="24">
23+
24+
<path
25+
android:fillColor="@android:color/white"
26+
android:pathData="M12,3v10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4V7h4V3h-6z" />
27+
28+
</vector>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Copyright (C) 2024 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:autoMirrored="true"
20+
android:tint="#000000"
21+
android:viewportHeight="24"
22+
android:viewportWidth="24">
23+
24+
<path
25+
android:fillColor="@android:color/white"
26+
android:pathData="M4.27,3L3,4.27l9,9v0.28c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4v-1.73L19.73,21 21,19.73 4.27,3zM14,7h4V3h-6v5.18l2,2z" />
27+
28+
</vector>

catalog/java/io/material/catalog/slider/res/layout/cat_slider_demo_corner.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,23 @@
6060
app:values="@array/initial_slider_multi_values"
6161
android:valueFrom="0.0"
6262
android:valueTo="11.0" />
63+
64+
<com.google.android.material.slider.Slider
65+
android:id="@+id/slider_icon"
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:layout_marginTop="32dp"
69+
android:layout_gravity="center"
70+
app:trackHeight="40dp"
71+
app:trackCornerSize="12dp"
72+
app:thumbHeight="48dp"
73+
app:trackIconActive="@drawable/baseline_music_note_24"
74+
app:trackIconActiveSize="20dp"
75+
app:trackIconActiveColor="@color/m3_slider_active_tick_marks_color"
76+
app:trackIconInactive="@drawable/baseline_music_off_24"
77+
app:trackIconInactiveSize="20dp"
78+
app:trackIconInactiveColor="@color/m3_slider_inactive_tick_marks_color"
79+
android:value="8.09"
80+
android:valueFrom="0.0"
81+
android:valueTo="11.0" />
6382
</LinearLayout>

docs/components/Slider.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,27 @@ slider also has tick marks.
292292

293293
#### Track attributes
294294

295-
| Element | Attribute | Related method(s) | Default value |
296-
|--------------------------------------------|------------------------------|-------------------------------------------------------------|--------------------------------------|
297-
| **Min value** | `android:valueFrom` | `setValueFrom`<br/>`getValueFrom` | N/A |
298-
| **Max value** | `android:valueTo` | `setValueTo`<br/>`getValueTo` | N/A |
299-
| **Step size (discrete)** | `android:stepSize` | `setStepSize`<br/>`getStepSize` | N/A |
300-
| **Initial selected value (Slider)** | `android:value` | `setValue`<br/>`getValue` | N/A |
301-
| **Initial selected values (RangeSlider)** | `app:values` | `setValues`<br/>`getValues` | N/A |
302-
| **Height** | `app:trackHeight` | `setTrackHeight`<br/>`getTrackHeight` | `16dp` |
303-
| **Color** | `app:trackColor` | `setTrackTintList`<br/>`getTrackTintList` | `null` |
304-
| **Color for track's active part** | `app:trackColorActive` | `setTrackActiveTintList`<br/>`getTrackActiveTintList` | `?attr/colorPrimary` |
305-
| **Color for track's inactive part** | `app:trackColorInactive` | `setTrackInactiveTintList`<br/>`getTrackInactiveTintList` | `?attr/colorSurfaceContainerHighest` |
306-
| **Corner size** | `app:trackCornerSize` | `setTrackCornerSize`<br/>`getTrackCornerSize` | `trackHeight / 2` |
307-
| **Inside corner size** | `app:trackInsideCornerSize` | `setTrackInsideCornerSize`<br/>`getTrackInsideCornerSize` | `2dp` |
308-
| **Stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`<br/>`getTrackStopIndicatorSize` | `4dp` |
309-
| **Minimum separation for adjacent thumbs** | `app:minSeparation` | `setMinSeparation`<br/>`getMinSeparation` | `0dp` |
295+
| Element | Attribute | Related method(s) | Default value |
296+
|--------------------------------------------|------------------------------|--------------------------------------------------------------------------------------|--------------------------------------|
297+
| **Min value** | `android:valueFrom` | `setValueFrom`<br/>`getValueFrom` | N/A |
298+
| **Max value** | `android:valueTo` | `setValueTo`<br/>`getValueTo` | N/A |
299+
| **Step size (discrete)** | `android:stepSize` | `setStepSize`<br/>`getStepSize` | N/A |
300+
| **Initial selected value (Slider)** | `android:value` | `setValue`<br/>`getValue` | N/A |
301+
| **Initial selected values (RangeSlider)** | `app:values` | `setValues`<br/>`getValues` | N/A |
302+
| **Height** | `app:trackHeight` | `setTrackHeight`<br/>`getTrackHeight` | `16dp` |
303+
| **Color** | `app:trackColor` | `setTrackTintList`<br/>`getTrackTintList` | `null` |
304+
| **Color for track's active part** | `app:trackColorActive` | `setTrackActiveTintList`<br/>`getTrackActiveTintList` | `?attr/colorPrimary` |
305+
| **Color for track's inactive part** | `app:trackColorInactive` | `setTrackInactiveTintList`<br/>`getTrackInactiveTintList` | `?attr/colorSurfaceContainerHighest` |
306+
| **Corner size** | `app:trackCornerSize` | `setTrackCornerSize`<br/>`getTrackCornerSize` | `trackHeight / 2` |
307+
| **Inside corner size** | `app:trackInsideCornerSize` | `setTrackInsideCornerSize`<br/>`getTrackInsideCornerSize` | `2dp` |
308+
| **Stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`<br/>`getTrackStopIndicatorSize` | `4dp` |
309+
| **Minimum separation for adjacent thumbs** | `app:minSeparation` | `setMinSeparation`<br/>`getMinSeparation` | `0dp` |
310+
| **Active icon** | `app:trackIconActive` | `setTrackIconActive`<br/>`setTrackIconActiveResource`<br/>`getTrackIconActive` | `null` |
311+
| **Active icon size** | `app:trackIconActiveSize` | `setTrackIconActiveSize`<br/>`getTrackIconActiveSize` | N/A |
312+
| **Active icon color** | `app:trackIconActiveColor` | `setTrackIconActiveColor`<br/>`getTrackIconActiveColor` | N/A |
313+
| **Inactive icon** | `app:trackIconInactive` | `setTrackIconInactive`<br/>`setTrackIconInactiveResource`<br/>`getTrackIconInactive` | `null` |
314+
| **Inactive icon size** | `app:trackIconInactiveSize` | `setTrackIconInactiveSize`<br/>`getTrackIconInactiveSize` | N/A |
315+
| **Inactive icon color** | `app:trackIconInactiveColor` | `setTrackIconInactiveColor`<br/>`getTrackIconInactiveColor` | N/A |
310316

311317
**Note:** `app:trackColor` takes precedence over `app:trackColorActive` and
312318
`app:trackColorInative`. It's a shorthand for setting both values to the same

0 commit comments

Comments
 (0)