Skip to content

Commit de1ff7c

Browse files
paulfthomaspekingme
authored andcommitted
[ChipGroup][a11y] Follow up
- make the reflow button toggleable - show reflow button selected state - show close icons on Chips in the reflow demo PiperOrigin-RevId: 759139390
1 parent 2749544 commit de1ff7c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

catalog/java/io/material/catalog/chip/ChipGroupDemoFragment.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private void initChipGroup(ChipGroup chipGroup, boolean showMenu) {
101101
viewAllChip.setChipIconResource(R.drawable.ic_drawer_menu_open_24px);
102102
viewAllChip.setChipIconTint(viewAllChip.getTextColors());
103103
viewAllChip.setChipIconVisible(true);
104+
viewAllChip.setCheckable(!showMenu);
104105
chipGroup.addView(viewAllChip);
105106

106107
PopupMenu menu;
@@ -111,10 +112,9 @@ private void initChipGroup(ChipGroup chipGroup, boolean showMenu) {
111112
menu = null;
112113
viewAllChip.setOnClickListener(
113114
v -> {
114-
if (chipGroup.isSingleLine()) {
115-
chipGroup.setSingleLine(false);
116-
initChipGroup(chipGroup, false);
117-
}
115+
chipGroup.setSingleLine(!chipGroup.isSingleLine());
116+
viewAllChip.setChecked(!chipGroup.isSingleLine());
117+
chipGroup.requestLayout();
118118
});
119119
}
120120

@@ -125,7 +125,6 @@ private void initChipGroup(ChipGroup chipGroup, boolean showMenu) {
125125
(Chip) getLayoutInflater().inflate(getChipGroupItem(singleSelection), chipGroup, false);
126126
chip.setId(i);
127127
chip.setText(textArray[i]);
128-
chip.setCloseIconVisible(false);
129128
chipGroup.addView(chip);
130129

131130
if (menu != null) {
@@ -138,8 +137,12 @@ private void initChipGroup(ChipGroup chipGroup, boolean showMenu) {
138137
menuItem.setChecked(targetChip.isChecked());
139138
return true;
140139
});
140+
chip.setCloseIconVisible(false);
141141
chip.setOnCheckedChangeListener(
142142
(buttonView, isChecked) -> menu.getMenu().getItem(chip.getId()).setChecked(isChecked));
143+
} else {
144+
chip.setCloseIconVisible(true);
145+
chip.setOnCloseIconClickListener(v -> chipGroup.removeView(chip));
143146
}
144147
}
145148
}

0 commit comments

Comments
 (0)