@@ -56,6 +56,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
5656 private int mTitleStyleRes ;
5757 private int mSubtitleStyleRes ;
5858 private Drawable mSplitBackground ;
59+ private boolean mTitleOptional ;
5960
6061 private Animator mCurrentAnimation ;
6162 private boolean mAnimateInOnLayout ;
@@ -354,7 +355,18 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
354355 }
355356
356357 if (mTitleLayout != null && mCustomView == null ) {
357- availableWidth = measureChildView (mTitleLayout , availableWidth , childSpecHeight , 0 );
358+ if (mTitleOptional ) {
359+ final int titleWidthSpec = MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED );
360+ mTitleLayout .measure (titleWidthSpec , childSpecHeight );
361+ final int titleWidth = mTitleLayout .getMeasuredWidth ();
362+ final boolean titleFits = titleWidth <= availableWidth ;
363+ if (titleFits ) {
364+ availableWidth -= titleWidth ;
365+ }
366+ mTitleLayout .setVisibility (titleFits ? VISIBLE : GONE );
367+ } else {
368+ availableWidth = measureChildView (mTitleLayout , availableWidth , childSpecHeight , 0 );
369+ }
358370 }
359371
360372 if (mCustomView != null ) {
@@ -460,7 +472,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
460472 }
461473 }
462474
463- if (mTitleLayout != null && mCustomView == null ) {
475+ if (mTitleLayout != null && mCustomView == null && mTitleLayout . getVisibility () != GONE ) {
464476 x += positionChild (mTitleLayout , x , y , contentHeight );
465477 }
466478
@@ -512,4 +524,15 @@ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
512524 super .onInitializeAccessibilityEvent (event );
513525 }
514526 }
527+
528+ public void setTitleOptional (boolean titleOptional ) {
529+ if (titleOptional != mTitleOptional ) {
530+ requestLayout ();
531+ }
532+ mTitleOptional = titleOptional ;
533+ }
534+
535+ public boolean isTitleOptional () {
536+ return mTitleOptional ;
537+ }
515538}
0 commit comments