@@ -241,6 +241,7 @@ abstract class BaseSlider<
241241 private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200 ;
242242 private static final int HALO_ALPHA = 63 ;
243243 private static final double THRESHOLD = .0001 ;
244+ private static final float THUMB_WIDTH_PRESSED_RATIO = .5f ;
244245
245246 static final int DEF_STYLE_RES = R .style .Widget_MaterialComponents_Slider ;
246247 static final int UNIT_VALUE = 1 ;
@@ -299,6 +300,8 @@ abstract class BaseSlider<
299300 private int thumbHeight ;
300301 private int haloRadius ;
301302 private int thumbTrackGapSize ;
303+ private int defaultThumbWidth = -1 ;
304+ private int defaultThumbTrackGapSize = -1 ;
302305 private int trackStopIndicatorSize ;
303306 private int trackInsideCornerSize ;
304307 private int labelPadding ;
@@ -2339,6 +2342,15 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
23392342 thumbIsPressed = true ;
23402343 snapTouchPosition ();
23412344 updateHaloHotspot ();
2345+ // Update the thumb width when pressed.
2346+ if (hasGapBetweenThumbAndTrack ()) {
2347+ defaultThumbWidth = thumbWidth ;
2348+ defaultThumbTrackGapSize = thumbTrackGapSize ;
2349+ int pressedThumbWidth = Math .round (thumbWidth * THUMB_WIDTH_PRESSED_RATIO );
2350+ int delta = thumbWidth - pressedThumbWidth ;
2351+ setThumbWidth (pressedThumbWidth );
2352+ setThumbTrackGapSize (thumbTrackGapSize - delta / 2 );
2353+ }
23422354 invalidate ();
23432355 onStartTrackingTouch ();
23442356 break ;
@@ -2378,6 +2390,13 @@ && abs(lastEvent.getY() - event.getY()) <= scaledTouchSlop) {
23782390 if (activeThumbIdx != -1 ) {
23792391 snapTouchPosition ();
23802392 updateHaloHotspot ();
2393+ // Reset the thumb width.
2394+ if (hasGapBetweenThumbAndTrack ()
2395+ && defaultThumbWidth != -1
2396+ && defaultThumbTrackGapSize != -1 ) {
2397+ setThumbWidth (defaultThumbWidth );
2398+ setThumbTrackGapSize (defaultThumbTrackGapSize );
2399+ }
23812400 activeThumbIdx = -1 ;
23822401 onStopTrackingTouch ();
23832402 }
0 commit comments