@@ -420,6 +420,8 @@ private void setNavigationIconDecorative(boolean decorative) {
420
420
// that, and restore the original background when the icon becomes clickable.
421
421
navigationIconButton .setBackgroundDrawable (
422
422
decorative ? null : originalNavigationIconBackground );
423
+
424
+ setHandwritingBoundsInsets ();
423
425
}
424
426
425
427
@ Override
@@ -448,6 +450,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
448
450
super .onLayout (changed , left , top , right , bottom );
449
451
450
452
layoutCenterView ();
453
+ setHandwritingBoundsInsets ();
451
454
}
452
455
453
456
@ Override
@@ -559,6 +562,32 @@ private void layoutChild(View child, int left, int top, int right, int bottom) {
559
562
}
560
563
}
561
564
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
+
562
591
/** Returns the optional centered child view of this {@link SearchBar} */
563
592
@ Nullable
564
593
public View getCenterView () {
0 commit comments