@@ -142,6 +142,8 @@ public class NavigationView extends ScrimInsetsFrameLayout implements MaterialBa
142
142
private OnGlobalLayoutListener onGlobalLayoutListener ;
143
143
private boolean topInsetScrimEnabled = true ;
144
144
private boolean bottomInsetScrimEnabled = true ;
145
+ private boolean startInsetScrimEnabled = true ;
146
+ private boolean endInsetScrimEnabled = true ;
145
147
146
148
@ Px private int drawerLayoutCornerSize = 0 ;
147
149
private final boolean drawerLayoutCornerSizeBackAnimationEnabled ;
@@ -328,6 +330,11 @@ public NavigationView(@NonNull Context context, @Nullable AttributeSet attrs, in
328
330
329
331
setBottomInsetScrimEnabled (
330
332
a .getBoolean (R .styleable .NavigationView_bottomInsetScrimEnabled , bottomInsetScrimEnabled ));
333
+ setStartInsetScrimEnabled (
334
+ a .getBoolean (R .styleable .NavigationView_startInsetScrimEnabled , startInsetScrimEnabled ));
335
+
336
+ setEndInsetScrimEnabled (
337
+ a .getBoolean (R .styleable .NavigationView_endInsetScrimEnabled , endInsetScrimEnabled ));
331
338
332
339
final int itemIconPadding =
333
340
a .getDimensionPixelSize (R .styleable .NavigationView_itemIconPadding , 0 );
@@ -933,6 +940,34 @@ public void setBottomInsetScrimEnabled(boolean enabled) {
933
940
this .bottomInsetScrimEnabled = enabled ;
934
941
}
935
942
943
+ /** Whether or not the NavigationView will draw a scrim behind the window's start inset. */
944
+ public boolean isStartInsetScrimEnabled () {
945
+ return this .startInsetScrimEnabled ;
946
+ }
947
+
948
+ /**
949
+ * Set whether or not the NavigationView should draw a scrim behind the window's start inset.
950
+ *
951
+ * @param enabled true when the NavigationView should draw a scrim.
952
+ */
953
+ public void setStartInsetScrimEnabled (boolean enabled ) {
954
+ this .startInsetScrimEnabled = enabled ;
955
+ }
956
+
957
+ /** Whether or not the NavigationView will draw a scrim behind the window's end inset. */
958
+ public boolean isEndInsetScrimEnabled () {
959
+ return this .endInsetScrimEnabled ;
960
+ }
961
+
962
+ /**
963
+ * Set whether or not the NavigationView should draw a scrim behind the window's end inset.
964
+ *
965
+ * @param enabled true when the NavigationView should draw a scrim.
966
+ */
967
+ public void setEndInsetScrimEnabled (boolean enabled ) {
968
+ this .endInsetScrimEnabled = enabled ;
969
+ }
970
+
936
971
/**
937
972
* Get the distance between the start edge of the NavigationView and the start of a menu divider.
938
973
*/
@@ -1087,10 +1122,12 @@ public void onGlobalLayout() {
1087
1122
presenter .setBehindStatusBar (isBehindStatusBar );
1088
1123
setDrawTopInsetForeground (isBehindStatusBar && isTopInsetScrimEnabled ());
1089
1124
1125
+ boolean isRtl = getLayoutDirection () == LAYOUT_DIRECTION_RTL ;
1090
1126
// The navigation view could be left aligned or just hidden out of view in a drawer
1091
1127
// layout when the global layout listener is called.
1092
1128
boolean isOnLeftSide = (tmpLocation [0 ] == 0 ) || (tmpLocation [0 ] + getWidth () == 0 );
1093
- setDrawLeftInsetForeground (isOnLeftSide );
1129
+ setDrawLeftInsetForeground (
1130
+ isOnLeftSide && (isRtl ? isEndInsetScrimEnabled () : isStartInsetScrimEnabled ()));
1094
1131
1095
1132
Activity activity = ContextUtils .getActivity (getContext ());
1096
1133
if (activity != null && VERSION .SDK_INT >= VERSION_CODES .LOLLIPOP ) {
@@ -1108,7 +1145,8 @@ public void onGlobalLayout() {
1108
1145
(displayBounds .width () == tmpLocation [0 ])
1109
1146
|| (displayBounds .width () - getWidth () == tmpLocation [0 ]);
1110
1147
1111
- setDrawRightInsetForeground (isOnRightSide );
1148
+ setDrawRightInsetForeground (
1149
+ isOnRightSide && (isRtl ? isStartInsetScrimEnabled () : isEndInsetScrimEnabled ()));
1112
1150
}
1113
1151
}
1114
1152
};
0 commit comments