1818
1919import android .content .Context ;
2020import android .content .res .Resources ;
21+ import android .content .res .TypedArray ;
2122import android .graphics .Rect ;
2223import android .graphics .drawable .Drawable ;
2324import android .text .TextUtils ;
@@ -46,8 +47,8 @@ public class ActionMenuItemView extends LinearLayout
4647 private ImageButton mImageButton ;
4748 private Button mTextButton ;
4849 private boolean mAllowTextWithIcon ;
49- private boolean mShowTextAllCaps ;
5050 private boolean mExpandedFormat ;
51+ private int mMinWidth ;
5152
5253 public ActionMenuItemView (Context context ) {
5354 this (context , null );
@@ -62,7 +63,11 @@ public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) {
6263 final Resources res = context .getResources ();
6364 mAllowTextWithIcon = res .getBoolean (
6465 com .android .internal .R .bool .config_allowActionMenuItemTextWithIcon );
65- mShowTextAllCaps = res .getBoolean (com .android .internal .R .bool .config_actionMenuItemAllCaps );
66+ TypedArray a = context .obtainStyledAttributes (attrs ,
67+ com .android .internal .R .styleable .ActionMenuItemView , 0 , 0 );
68+ mMinWidth = a .getDimensionPixelSize (
69+ com .android .internal .R .styleable .ActionMenuItemView_minWidth , 0 );
70+ a .recycle ();
6671 }
6772
6873 @ Override
@@ -228,4 +233,21 @@ public boolean onLongClick(View v) {
228233 cheatSheet .show ();
229234 return true ;
230235 }
236+
237+ @ Override
238+ protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
239+ super .onMeasure (widthMeasureSpec , heightMeasureSpec );
240+
241+ final int widthMode = MeasureSpec .getMode (widthMeasureSpec );
242+ final int specSize = MeasureSpec .getSize (widthMeasureSpec );
243+ final int oldMeasuredWidth = getMeasuredWidth ();
244+ final int targetWidth = widthMode == MeasureSpec .AT_MOST ? Math .min (specSize , mMinWidth )
245+ : mMinWidth ;
246+
247+ if (widthMode != MeasureSpec .EXACTLY && mMinWidth > 0 && oldMeasuredWidth < targetWidth ) {
248+ // Remeasure at exactly the minimum width.
249+ super .onMeasure (MeasureSpec .makeMeasureSpec (targetWidth , MeasureSpec .EXACTLY ),
250+ heightMeasureSpec );
251+ }
252+ }
231253}
0 commit comments