Skip to content

Commit bce4d98

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "View pressed state dispatching tweaks"
2 parents 74c9610 + 035a1fc commit bce4d98

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

core/java/android/view/View.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,16 +5048,17 @@ public void setLongClickable(boolean longClickable) {
50485048
* the View's internal state from a previously set "pressed" state.
50495049
*/
50505050
public void setPressed(boolean pressed) {
5051-
if (pressed == ((mPrivateFlags & PRESSED) == PRESSED)) {
5052-
return;
5053-
}
5051+
final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED);
50545052

50555053
if (pressed) {
50565054
mPrivateFlags |= PRESSED;
50575055
} else {
50585056
mPrivateFlags &= ~PRESSED;
50595057
}
5060-
refreshDrawableState();
5058+
5059+
if (needsRefresh) {
5060+
refreshDrawableState();
5061+
}
50615062
dispatchSetPressed(pressed);
50625063
}
50635064

core/java/android/view/ViewGroup.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,13 @@ protected void dispatchSetPressed(boolean pressed) {
27702770
final View[] children = mChildren;
27712771
final int count = mChildrenCount;
27722772
for (int i = 0; i < count; i++) {
2773-
children[i].setPressed(pressed);
2773+
final View child = children[i];
2774+
// Children that are clickable on their own should not
2775+
// show a pressed state when their parent view does.
2776+
// Clearing a pressed state always propagates.
2777+
if (!pressed || (!child.isClickable() && !child.isLongClickable())) {
2778+
child.setPressed(pressed);
2779+
}
27742780
}
27752781
}
27762782

0 commit comments

Comments
 (0)