From a7ff8c9006b69cbfcc346f74ed8a9ebad6661346 Mon Sep 17 00:00:00 2001 From: rightnao Date: Fri, 20 Dec 2024 23:43:50 +0000 Subject: [PATCH] [Chip] Fix close icon focus ripple PiperOrigin-RevId: 708446508 --- lib/java/com/google/android/material/chip/Chip.java | 2 ++ .../com/google/android/material/chip/ChipDrawable.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/java/com/google/android/material/chip/Chip.java b/lib/java/com/google/android/material/chip/Chip.java index ae11f870e38..ee1877241c7 100644 --- a/lib/java/com/google/android/material/chip/Chip.java +++ b/lib/java/com/google/android/material/chip/Chip.java @@ -985,6 +985,8 @@ protected void getVisibleVirtualViews(@NonNull List virtualViewIds) { protected void onVirtualViewKeyboardFocusChanged(int virtualViewId, boolean hasFocus) { if (virtualViewId == CLOSE_ICON_VIRTUAL_ID) { closeIconFocused = hasFocus; + } + if (chipDrawable.refreshCloseIconFocus(closeIconFocused)) { refreshDrawableState(); } } diff --git a/lib/java/com/google/android/material/chip/ChipDrawable.java b/lib/java/com/google/android/material/chip/ChipDrawable.java index 95cb2ce58fa..3d1c951a361 100644 --- a/lib/java/com/google/android/material/chip/ChipDrawable.java +++ b/lib/java/com/google/android/material/chip/ChipDrawable.java @@ -1396,6 +1396,14 @@ public void setTextColor(@Nullable ColorStateList color) { } } + boolean refreshCloseIconFocus(boolean closeIconFocused) { + boolean changed = false; + if (closeIcon != null) { + changed = setCloseIconState(closeIconFocused ? new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled} : DEFAULT_STATE); + } + return changed; + } + /** Delegate interface to be implemented by Views that own a ChipDrawable. */ public interface Delegate {