Commit a3af20a authored and committed Mar 21, 2024
1 parent d61cffd commit a3af20a Copy full SHA for a3af20a
File tree 5 files changed +37
-5
lines changed
catalog/java/io/material/catalog/navigationdrawer
lib/java/com/google/android/material/internal
5 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ public void handleOnBackPressed() {
46
46
};
47
47
48
48
private DrawerLayout drawerLayout ;
49
+ private MaterialSwitch autoCloseSwitch ;
49
50
50
51
@ NonNull
51
52
@ Override
@@ -91,13 +92,13 @@ public void onDrawerClosed(@NonNull View drawerView) {
91
92
view .findViewById (R .id .show_end_drawer_gravity )
92
93
.setOnClickListener (v -> drawerLayout .openDrawer (navigationViewEnd ));
93
94
94
- MaterialSwitch materialSwitch = view .findViewById (R .id .bold_text_switch );
95
- materialSwitch .setChecked (true );
96
- materialSwitch .setOnCheckedChangeListener (
95
+ MaterialSwitch boldTextSwitch = view .findViewById (R .id .bold_text_switch );
96
+ boldTextSwitch .setOnCheckedChangeListener (
97
97
(buttonView , isChecked ) -> {
98
98
navigationViewStart .setItemTextAppearanceActiveBoldEnabled (isChecked );
99
99
navigationViewEnd .setItemTextAppearanceActiveBoldEnabled (isChecked );
100
100
});
101
+ autoCloseSwitch = view .findViewById (R .id .auto_close_switch );
101
102
102
103
drawerLayout .post (
103
104
() -> {
@@ -115,7 +116,9 @@ private void initNavigationView(NavigationView navigationView) {
115
116
navigationView .setNavigationItemSelectedListener (
116
117
menuItem -> {
117
118
navigationView .setCheckedItem (menuItem );
118
- drawerLayout .closeDrawer (navigationView );
119
+ if (autoCloseSwitch .isChecked ()) {
120
+ drawerLayout .closeDrawer (navigationView );
121
+ }
119
122
return true ;
120
123
});
121
124
}
Original file line number Diff line number Diff line change 80
80
android : id =" @+id/bold_text_switch"
81
81
android : layout_width =" wrap_content"
82
82
android : layout_height =" wrap_content"
83
+ android : checked =" true"
84
+ android : layout_marginStart =" 12dp" />
85
+ </LinearLayout >
86
+
87
+ <LinearLayout
88
+ android : layout_width =" wrap_content"
89
+ android : layout_height =" wrap_content"
90
+ android : orientation =" horizontal" >
91
+ <TextView
92
+ android : layout_width =" wrap_content"
93
+ android : layout_height =" wrap_content"
94
+ android : layout_gravity =" end|center_vertical"
95
+ android : labelFor =" @+id/auto_close_switch"
96
+ android : text =" @string/cat_navigationdrawer_label_auto_close" />
97
+ <com .google.android.material.materialswitch.MaterialSwitch
98
+ android : id =" @+id/auto_close_switch"
99
+ android : layout_width =" wrap_content"
100
+ android : layout_height =" wrap_content"
101
+ android : checked =" true"
83
102
android : layout_marginStart =" 12dp" />
84
103
</LinearLayout >
85
104
Original file line number Diff line number Diff line change 35
35
Open End Drawer
36
36
</string >
37
37
<string name =" cat_navigationdrawer_label_active_bold" translatable =" false" >Bold active label</string >
38
+ <string name =" cat_navigationdrawer_label_auto_close" translatable =" false" >Close drawer on selection</string >
38
39
<string name =" cat_navigationdrawer_header_mail" >Mail</string >
39
40
<string name =" cat_navigationdrawer_header_labels" >Labels</string >
40
41
<string name =" cat_navigationdrawer_label" >Label</string >
Original file line number Diff line number Diff line change 34
34
import android .util .TypedValue ;
35
35
import android .view .LayoutInflater ;
36
36
import android .view .View ;
37
+ import android .view .ViewGroup ;
37
38
import android .view .ViewStub ;
38
39
import android .widget .CheckedTextView ;
39
40
import android .widget .FrameLayout ;
@@ -173,6 +174,10 @@ private void setActionView(@Nullable View actionView) {
173
174
(FrameLayout )
174
175
((ViewStub ) findViewById (R .id .design_menu_item_action_area_stub )).inflate ();
175
176
}
177
+ // Make sure to remove the existing parent if the View is reused
178
+ if (actionView .getParent () != null ) {
179
+ ((ViewGroup ) actionView .getParent ()).removeView (actionView );
180
+ }
176
181
actionArea .removeAllViews ();
177
182
actionArea .addView (actionView );
178
183
}
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ public class NavigationMenuPresenter implements MenuPresenter {
105
105
106
106
/** Padding for separators between items */
107
107
int paddingSeparator ;
108
+
108
109
private int overScrollMode = -1 ;
109
110
110
111
@ Override
@@ -125,6 +126,9 @@ public MenuView getMenuView(ViewGroup root) {
125
126
new NavigationMenuViewAccessibilityDelegate (menuView ));
126
127
if (adapter == null ) {
127
128
adapter = new NavigationMenuAdapter ();
129
+ // Prevent recreating all the Views when notifyDataSetChanged() is called causing issues
130
+ // with the a11y reader (see b/112931425)
131
+ adapter .setHasStableIds (true );
128
132
}
129
133
if (overScrollMode != -1 ) {
130
134
menuView .setOverScrollMode (overScrollMode );
@@ -375,7 +379,7 @@ public int getSubheaderInsetEnd() {
375
379
return this .subheaderInsetEnd ;
376
380
}
377
381
378
- public void setSubheaderInsetEnd (@ Px int subheaderInsetEnd ) {
382
+ public void setSubheaderInsetEnd (@ Px int subheaderInsetEnd ) {
379
383
this .subheaderInsetEnd = subheaderInsetEnd ;
380
384
updateMenuView (false );
381
385
}
You can’t perform that action at this time.
0 commit comments