File tree Expand file tree Collapse file tree 5 files changed +37
-5
lines changed
catalog/java/io/material/catalog/navigationdrawer
lib/java/com/google/android/material/internal Expand file tree Collapse file tree 5 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ public void handleOnBackPressed() {
4646 };
4747
4848 private DrawerLayout drawerLayout ;
49+ private MaterialSwitch autoCloseSwitch ;
4950
5051 @ NonNull
5152 @ Override
@@ -91,13 +92,13 @@ public void onDrawerClosed(@NonNull View drawerView) {
9192 view .findViewById (R .id .show_end_drawer_gravity )
9293 .setOnClickListener (v -> drawerLayout .openDrawer (navigationViewEnd ));
9394
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 (
9797 (buttonView , isChecked ) -> {
9898 navigationViewStart .setItemTextAppearanceActiveBoldEnabled (isChecked );
9999 navigationViewEnd .setItemTextAppearanceActiveBoldEnabled (isChecked );
100100 });
101+ autoCloseSwitch = view .findViewById (R .id .auto_close_switch );
101102
102103 drawerLayout .post (
103104 () -> {
@@ -115,7 +116,9 @@ private void initNavigationView(NavigationView navigationView) {
115116 navigationView .setNavigationItemSelectedListener (
116117 menuItem -> {
117118 navigationView .setCheckedItem (menuItem );
118- drawerLayout .closeDrawer (navigationView );
119+ if (autoCloseSwitch .isChecked ()) {
120+ drawerLayout .closeDrawer (navigationView );
121+ }
119122 return true ;
120123 });
121124 }
Original file line number Diff line number Diff line change 8080 android : id =" @+id/bold_text_switch"
8181 android : layout_width =" wrap_content"
8282 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"
83102 android : layout_marginStart =" 12dp" />
84103 </LinearLayout >
85104
Original file line number Diff line number Diff line change 3535 Open End Drawer
3636 </string >
3737 <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 >
3839 <string name =" cat_navigationdrawer_header_mail" >Mail</string >
3940 <string name =" cat_navigationdrawer_header_labels" >Labels</string >
4041 <string name =" cat_navigationdrawer_label" >Label</string >
Original file line number Diff line number Diff line change 3434import android .util .TypedValue ;
3535import android .view .LayoutInflater ;
3636import android .view .View ;
37+ import android .view .ViewGroup ;
3738import android .view .ViewStub ;
3839import android .widget .CheckedTextView ;
3940import android .widget .FrameLayout ;
@@ -173,6 +174,10 @@ private void setActionView(@Nullable View actionView) {
173174 (FrameLayout )
174175 ((ViewStub ) findViewById (R .id .design_menu_item_action_area_stub )).inflate ();
175176 }
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+ }
176181 actionArea .removeAllViews ();
177182 actionArea .addView (actionView );
178183 }
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ public class NavigationMenuPresenter implements MenuPresenter {
105105
106106 /** Padding for separators between items */
107107 int paddingSeparator ;
108+
108109 private int overScrollMode = -1 ;
109110
110111 @ Override
@@ -125,6 +126,9 @@ public MenuView getMenuView(ViewGroup root) {
125126 new NavigationMenuViewAccessibilityDelegate (menuView ));
126127 if (adapter == null ) {
127128 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 );
128132 }
129133 if (overScrollMode != -1 ) {
130134 menuView .setOverScrollMode (overScrollMode );
@@ -375,7 +379,7 @@ public int getSubheaderInsetEnd() {
375379 return this .subheaderInsetEnd ;
376380 }
377381
378- public void setSubheaderInsetEnd (@ Px int subheaderInsetEnd ) {
382+ public void setSubheaderInsetEnd (@ Px int subheaderInsetEnd ) {
379383 this .subheaderInsetEnd = subheaderInsetEnd ;
380384 updateMenuView (false );
381385 }
You can’t perform that action at this time.
0 commit comments