@@ -420,6 +420,8 @@ private void setNavigationIconDecorative(boolean decorative) {
420420 // that, and restore the original background when the icon becomes clickable.
421421 navigationIconButton .setBackgroundDrawable (
422422 decorative ? null : originalNavigationIconBackground );
423+
424+ setHandwritingBoundsInsets ();
423425 }
424426
425427 @ Override
@@ -448,6 +450,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
448450 super .onLayout (changed , left , top , right , bottom );
449451
450452 layoutCenterView ();
453+ setHandwritingBoundsInsets ();
451454 }
452455
453456 @ Override
@@ -559,6 +562,32 @@ private void layoutChild(View child, int left, int top, int right, int bottom) {
559562 }
560563 }
561564
565+ private void setHandwritingBoundsInsets () {
566+ if (VERSION .SDK_INT < VERSION_CODES .UPSIDE_DOWN_CAKE ) {
567+ return ;
568+ }
569+
570+ boolean isRtl = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
571+
572+ // If the navigation icon is non-decorative, exclude it from the handwriting bounds.
573+ int startInset = 0 ;
574+ View navigationIconButton = ToolbarUtils .getNavigationIconButton (this );
575+ if (navigationIconButton != null && navigationIconButton .isClickable ()) {
576+ startInset =
577+ isRtl ? (getWidth () - navigationIconButton .getLeft ()) : navigationIconButton .getRight ();
578+ }
579+
580+ // Exclude the menu items from the handwriting bounds.
581+ int endInset = 0 ;
582+ View actionMenuView = ToolbarUtils .getActionMenuView (this );
583+ if (actionMenuView != null ) {
584+ endInset = isRtl ? actionMenuView .getRight () : (getWidth () - actionMenuView .getLeft ());
585+ }
586+
587+ setHandwritingBoundsOffsets (
588+ -(isRtl ? endInset : startInset ), 0 , -(isRtl ? startInset : endInset ), 0 );
589+ }
590+
562591 /** Returns the optional centered child view of this {@link SearchBar} */
563592 @ Nullable
564593 public View getCenterView () {
0 commit comments