/* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.widget; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActionBar; import android.content.Context; import android.content.res.TypedArray; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; import android.text.Layout; import android.text.TextUtils; import android.util.AttributeSet; import android.view.CollapsibleActionView; import android.view.ContextThemeWrapper; import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import com.android.internal.R; import com.android.internal.view.menu.MenuBuilder; import com.android.internal.view.menu.MenuItemImpl; import com.android.internal.view.menu.MenuPresenter; import com.android.internal.view.menu.MenuView; import com.android.internal.view.menu.SubMenuBuilder; import com.android.internal.widget.DecorToolbar; import com.android.internal.widget.ToolbarWidgetWrapper; import java.util.ArrayList; import java.util.List; /** * A standard toolbar for use within application content. * *
A Toolbar is a generalization of {@link android.app.ActionBar action bars} for use * within application layouts. While an action bar is traditionally part of an * {@link android.app.Activity Activity's} opaque window decor controlled by the framework, * a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. * An application may choose to designate a Toolbar as the action bar for an Activity * using the {@link android.app.Activity#setActionBar(Toolbar) setActionBar()} method.
* *Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar * may contain a combination of the following optional elements: * *
In modern Android UIs developers should lean more on a visually distinct color scheme for * toolbars than on their application icon. The use of application icon plus title as a standard * layout is discouraged on API 21 devices and newer.
*/ public class Toolbar extends ViewGroup { private static final String TAG = "Toolbar"; private ActionMenuView mMenuView; private TextView mTitleTextView; private TextView mSubtitleTextView; private ImageButton mNavButtonView; private ImageView mLogoView; private Drawable mCollapseIcon; private CharSequence mCollapseDescription; private ImageButton mCollapseButtonView; View mExpandedActionView; /** Context against which to inflate popup menus. */ private Context mPopupContext; /** Theme resource against which to inflate popup menus. */ private int mPopupTheme; private int mTitleTextAppearance; private int mSubtitleTextAppearance; private int mNavButtonStyle; private int mButtonGravity; private int mMaxButtonHeight; private int mTitleMarginStart; private int mTitleMarginEnd; private int mTitleMarginTop; private int mTitleMarginBottom; private final RtlSpacingHelper mContentInsets = new RtlSpacingHelper(); private int mGravity = Gravity.START | Gravity.CENTER_VERTICAL; private CharSequence mTitleText; private CharSequence mSubtitleText; private int mTitleTextColor; private int mSubtitleTextColor; private boolean mEatingTouch; // Clear me after use. private final ArrayListThis drawable should generally take the place of title text. The logo cannot be * clicked. Apps using a logo should also supply a description using * {@link #setLogoDescription(int)}.
* * @param resId ID of a drawable resource */ public void setLogo(int resId) { setLogo(getContext().getDrawable(resId)); } /** @hide */ public boolean canShowOverflowMenu() { return getVisibility() == VISIBLE && mMenuView != null && mMenuView.isOverflowReserved(); } /** * Check whether the overflow menu is currently showing. This may not reflect * a pending show operation in progress. * * @return true if the overflow menu is currently showing */ public boolean isOverflowMenuShowing() { return mMenuView != null && mMenuView.isOverflowMenuShowing(); } /** @hide */ public boolean isOverflowMenuShowPending() { return mMenuView != null && mMenuView.isOverflowMenuShowPending(); } /** * Show the overflow items from the associated menu. * * @return true if the menu was able to be shown, false otherwise */ public boolean showOverflowMenu() { return mMenuView != null && mMenuView.showOverflowMenu(); } /** * Hide the overflow items from the associated menu. * * @return true if the menu was able to be hidden, false otherwise */ public boolean hideOverflowMenu() { return mMenuView != null && mMenuView.hideOverflowMenu(); } /** @hide */ public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) { if (menu == null && mMenuView == null) { return; } ensureMenuView(); final MenuBuilder oldMenu = mMenuView.peekMenu(); if (oldMenu == menu) { return; } if (oldMenu != null) { oldMenu.removeMenuPresenter(mOuterActionMenuPresenter); oldMenu.removeMenuPresenter(mExpandedMenuPresenter); } if (mExpandedMenuPresenter == null) { mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); } outerPresenter.setExpandedActionViewsExclusive(true); if (menu != null) { menu.addMenuPresenter(outerPresenter, mPopupContext); menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext); } else { outerPresenter.initForMenu(mPopupContext, null); mExpandedMenuPresenter.initForMenu(mPopupContext, null); outerPresenter.updateMenuView(true); mExpandedMenuPresenter.updateMenuView(true); } mMenuView.setPopupTheme(mPopupTheme); mMenuView.setPresenter(outerPresenter); mOuterActionMenuPresenter = outerPresenter; } /** * Dismiss all currently showing popup menus, including overflow or submenus. */ public void dismissPopupMenus() { if (mMenuView != null) { mMenuView.dismissPopupMenus(); } } /** @hide */ public boolean isTitleTruncated() { if (mTitleTextView == null) { return false; } final Layout titleLayout = mTitleTextView.getLayout(); if (titleLayout == null) { return false; } final int lineCount = titleLayout.getLineCount(); for (int i = 0; i < lineCount; i++) { if (titleLayout.getEllipsisCount(i) > 0) { return true; } } return false; } /** * Set a logo drawable. * *This drawable should generally take the place of title text. The logo cannot be * clicked. Apps using a logo should also supply a description using * {@link #setLogoDescription(int)}.
* * @param drawable Drawable to use as a logo */ public void setLogo(Drawable drawable) { if (drawable != null) { ensureLogoView(); if (mLogoView.getParent() == null) { addSystemView(mLogoView); updateChildVisibilityForExpandedActionView(mLogoView); } } else if (mLogoView != null && mLogoView.getParent() != null) { removeView(mLogoView); } if (mLogoView != null) { mLogoView.setImageDrawable(drawable); } } /** * Return the current logo drawable. * * @return The current logo drawable * @see #setLogo(int) * @see #setLogo(android.graphics.drawable.Drawable) */ public Drawable getLogo() { return mLogoView != null ? mLogoView.getDrawable() : null; } /** * Set a description of the toolbar's logo. * *This description will be used for accessibility or other similar descriptions * of the UI.
* * @param resId String resource id */ public void setLogoDescription(int resId) { setLogoDescription(getContext().getText(resId)); } /** * Set a description of the toolbar's logo. * *This description will be used for accessibility or other similar descriptions * of the UI.
* * @param description Description to set */ public void setLogoDescription(CharSequence description) { if (!TextUtils.isEmpty(description)) { ensureLogoView(); } if (mLogoView != null) { mLogoView.setContentDescription(description); } } /** * Return the description of the toolbar's logo. * * @return A description of the logo */ public CharSequence getLogoDescription() { return mLogoView != null ? mLogoView.getContentDescription() : null; } private void ensureLogoView() { if (mLogoView == null) { mLogoView = new ImageView(getContext()); } } /** * Check whether this Toolbar is currently hosting an expanded action view. * *An action view may be expanded either directly from the * {@link android.view.MenuItem MenuItem} it belongs to or by user action. If the Toolbar * has an expanded action view it can be collapsed using the {@link #collapseActionView()} * method.
* * @return true if the Toolbar has an expanded action view */ public boolean hasExpandedActionView() { return mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null; } /** * Collapse a currently expanded action view. If this Toolbar does not have an * expanded action view this method has no effect. * *An action view may be expanded either directly from the * {@link android.view.MenuItem MenuItem} it belongs to or by user action.
* * @see #hasExpandedActionView() */ public void collapseActionView() { final MenuItemImpl item = mExpandedMenuPresenter == null ? null : mExpandedMenuPresenter.mCurrentExpandedItem; if (item != null) { item.collapseActionView(); } } /** * Returns the title of this toolbar. * * @return The current title. */ public CharSequence getTitle() { return mTitleText; } /** * Set the title of this toolbar. * *A title should be used as the anchor for a section of content. It should * describe or name the content being viewed.
* * @param resId Resource ID of a string to set as the title */ public void setTitle(int resId) { setTitle(getContext().getText(resId)); } /** * Set the title of this toolbar. * *A title should be used as the anchor for a section of content. It should * describe or name the content being viewed.
* * @param title Title to set */ public void setTitle(CharSequence title) { if (!TextUtils.isEmpty(title)) { if (mTitleTextView == null) { final Context context = getContext(); mTitleTextView = new TextView(context); mTitleTextView.setSingleLine(); mTitleTextView.setEllipsize(TextUtils.TruncateAt.END); if (mTitleTextAppearance != 0) { mTitleTextView.setTextAppearance(context, mTitleTextAppearance); } if (mTitleTextColor != 0) { mTitleTextView.setTextColor(mTitleTextColor); } } if (mTitleTextView.getParent() == null) { addSystemView(mTitleTextView); updateChildVisibilityForExpandedActionView(mTitleTextView); } } else if (mTitleTextView != null && mTitleTextView.getParent() != null) { removeView(mTitleTextView); } if (mTitleTextView != null) { mTitleTextView.setText(title); } mTitleText = title; } /** * Return the subtitle of this toolbar. * * @return The current subtitle */ public CharSequence getSubtitle() { return mSubtitleText; } /** * Set the subtitle of this toolbar. * *Subtitles should express extended information about the current content.
* * @param resId String resource ID */ public void setSubtitle(int resId) { setSubtitle(getContext().getText(resId)); } /** * Set the subtitle of this toolbar. * *Subtitles should express extended information about the current content.
* * @param subtitle Subtitle to set */ public void setSubtitle(CharSequence subtitle) { if (!TextUtils.isEmpty(subtitle)) { if (mSubtitleTextView == null) { final Context context = getContext(); mSubtitleTextView = new TextView(context); mSubtitleTextView.setSingleLine(); mSubtitleTextView.setEllipsize(TextUtils.TruncateAt.END); if (mSubtitleTextAppearance != 0) { mSubtitleTextView.setTextAppearance(context, mSubtitleTextAppearance); } if (mSubtitleTextColor != 0) { mSubtitleTextView.setTextColor(mSubtitleTextColor); } } if (mSubtitleTextView.getParent() == null) { addSystemView(mSubtitleTextView); updateChildVisibilityForExpandedActionView(mSubtitleTextView); } } else if (mSubtitleTextView != null && mSubtitleTextView.getParent() != null) { removeView(mSubtitleTextView); } if (mSubtitleTextView != null) { mSubtitleTextView.setText(subtitle); } mSubtitleText = subtitle; } /** * Sets the text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. */ public void setTitleTextAppearance(Context context, int resId) { mTitleTextAppearance = resId; if (mTitleTextView != null) { mTitleTextView.setTextAppearance(context, resId); } } /** * Sets the text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. */ public void setSubtitleTextAppearance(Context context, int resId) { mSubtitleTextAppearance = resId; if (mSubtitleTextView != null) { mSubtitleTextView.setTextAppearance(context, resId); } } /** * Sets the text color of the title, if present. * * @param color The new text color in 0xAARRGGBB format */ public void setTitleTextColor(int color) { mTitleTextColor = color; if (mTitleTextView != null) { mTitleTextView.setTextColor(color); } } /** * Sets the text color of the subtitle, if present. * * @param color The new text color in 0xAARRGGBB format */ public void setSubtitleTextColor(int color) { mSubtitleTextColor = color; if (mSubtitleTextView != null) { mSubtitleTextView.setTextColor(color); } } /** * Retrieve the currently configured content description for the navigation button view. * This will be used to describe the navigation action to users through mechanisms such * as screen readers or tooltips. * * @return The navigation button's content description * * @attr ref android.R.styleable#Toolbar_navigationContentDescription */ @Nullable public CharSequence getNavigationContentDescription() { return mNavButtonView != null ? mNavButtonView.getContentDescription() : null; } /** * Set a content description for the navigation button if one is present. The content * description will be read via screen readers or other accessibility systems to explain * the action of the navigation button. * * @param resId Resource ID of a content description string to set, or 0 to * clear the description * * @attr ref android.R.styleable#Toolbar_navigationContentDescription */ public void setNavigationContentDescription(int resId) { setNavigationContentDescription(resId != 0 ? getContext().getText(resId) : null); } /** * Set a content description for the navigation button if one is present. The content * description will be read via screen readers or other accessibility systems to explain * the action of the navigation button. * * @param description Content description to set, ornull
to
* clear the content description
*
* @attr ref android.R.styleable#Toolbar_navigationContentDescription
*/
public void setNavigationContentDescription(@Nullable CharSequence description) {
if (!TextUtils.isEmpty(description)) {
ensureNavButtonView();
}
if (mNavButtonView != null) {
mNavButtonView.setContentDescription(description);
}
}
/**
* Set the icon to use for the toolbar's navigation button.
*
* The navigation button appears at the start of the toolbar if present. Setting an icon * will make the navigation button visible.
* *If you use a navigation icon you should also set a description for its action using * {@link #setNavigationContentDescription(int)}. This is used for accessibility and * tooltips.
* * @param resId Resource ID of a drawable to set * * @attr ref android.R.styleable#Toolbar_navigationIcon */ public void setNavigationIcon(int resId) { setNavigationIcon(getContext().getDrawable(resId)); } /** * Set the icon to use for the toolbar's navigation button. * *The navigation button appears at the start of the toolbar if present. Setting an icon * will make the navigation button visible.
* *If you use a navigation icon you should also set a description for its action using * {@link #setNavigationContentDescription(int)}. This is used for accessibility and * tooltips.
* * @param icon Drawable to set, may be null to clear the icon * * @attr ref android.R.styleable#Toolbar_navigationIcon */ public void setNavigationIcon(@Nullable Drawable icon) { if (icon != null) { ensureNavButtonView(); if (mNavButtonView.getParent() == null) { addSystemView(mNavButtonView); updateChildVisibilityForExpandedActionView(mNavButtonView); } } else if (mNavButtonView != null && mNavButtonView.getParent() != null) { removeView(mNavButtonView); } if (mNavButtonView != null) { mNavButtonView.setImageDrawable(icon); } } /** * Return the current drawable used as the navigation icon. * * @return The navigation icon drawable * * @attr ref android.R.styleable#Toolbar_navigationIcon */ @Nullable public Drawable getNavigationIcon() { return mNavButtonView != null ? mNavButtonView.getDrawable() : null; } /** * Set a listener to respond to navigation events. * *This listener will be called whenever the user clicks the navigation button * at the start of the toolbar. An icon must be set for the navigation button to appear.
* * @param listener Listener to set * @see #setNavigationIcon(android.graphics.drawable.Drawable) */ public void setNavigationOnClickListener(OnClickListener listener) { ensureNavButtonView(); mNavButtonView.setOnClickListener(listener); } /** * Return the Menu shown in the toolbar. * *Applications that wish to populate the toolbar's menu can do so from here. To use * an XML menu resource, use {@link #inflateMenu(int)}.
* * @return The toolbar's Menu */ public Menu getMenu() { ensureMenu(); return mMenuView.getMenu(); } private void ensureMenu() { ensureMenuView(); if (mMenuView.peekMenu() == null) { // Initialize a new menu for the first time. final MenuBuilder menu = (MenuBuilder) mMenuView.getMenu(); if (mExpandedMenuPresenter == null) { mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); } mMenuView.setExpandedActionViewsExclusive(true); menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext); } } private void ensureMenuView() { if (mMenuView == null) { mMenuView = new ActionMenuView(getContext()); mMenuView.setPopupTheme(mPopupTheme); mMenuView.setOnMenuItemClickListener(mMenuViewItemClickListener); mMenuView.setMenuCallbacks(mActionMenuPresenterCallback, mMenuBuilderCallback); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = Gravity.END | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); mMenuView.setLayoutParams(lp); addSystemView(mMenuView); } } private MenuInflater getMenuInflater() { return new MenuInflater(getContext()); } /** * Inflate a menu resource into this toolbar. * *Inflate an XML menu resource into this toolbar. Existing items in the menu will not * be modified or removed.
* * @param resId ID of a menu resource to inflate */ public void inflateMenu(int resId) { getMenuInflater().inflate(resId, getMenu()); } /** * Set a listener to respond to menu item click events. * *This listener will be invoked whenever a user selects a menu item from * the action buttons presented at the end of the toolbar or the associated overflow.
* * @param listener Listener to set */ public void setOnMenuItemClickListener(OnMenuItemClickListener listener) { mOnMenuItemClickListener = listener; } /** * Set the content insets for this toolbar relative to layout direction. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @param contentInsetStart Content inset for the toolbar starting edge * @param contentInsetEnd Content inset for the toolbar ending edge * * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetStart() * @see #getContentInsetEnd() * @see #getContentInsetLeft() * @see #getContentInsetRight() */ public void setContentInsetsRelative(int contentInsetStart, int contentInsetEnd) { mContentInsets.setRelative(contentInsetStart, contentInsetEnd); } /** * Get the starting content inset for this toolbar. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @return The starting content inset for this toolbar * * @see #setContentInsetsRelative(int, int) * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetEnd() * @see #getContentInsetLeft() * @see #getContentInsetRight() */ public int getContentInsetStart() { return mContentInsets.getStart(); } /** * Get the ending content inset for this toolbar. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @return The ending content inset for this toolbar * * @see #setContentInsetsRelative(int, int) * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetStart() * @see #getContentInsetLeft() * @see #getContentInsetRight() */ public int getContentInsetEnd() { return mContentInsets.getEnd(); } /** * Set the content insets for this toolbar. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @param contentInsetLeft Content inset for the toolbar's left edge * @param contentInsetRight Content inset for the toolbar's right edge * * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetStart() * @see #getContentInsetEnd() * @see #getContentInsetLeft() * @see #getContentInsetRight() */ public void setContentInsetsAbsolute(int contentInsetLeft, int contentInsetRight) { mContentInsets.setAbsolute(contentInsetLeft, contentInsetRight); } /** * Get the left content inset for this toolbar. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @return The left content inset for this toolbar * * @see #setContentInsetsRelative(int, int) * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetStart() * @see #getContentInsetEnd() * @see #getContentInsetRight() */ public int getContentInsetLeft() { return mContentInsets.getLeft(); } /** * Get the right content inset for this toolbar. * *The content inset affects the valid area for Toolbar content other than * the navigation button and menu. Insets define the minimum margin for these components * and can be used to effectively align Toolbar content along well-known gridlines.
* * @return The right content inset for this toolbar * * @see #setContentInsetsRelative(int, int) * @see #setContentInsetsAbsolute(int, int) * @see #getContentInsetStart() * @see #getContentInsetEnd() * @see #getContentInsetLeft() */ public int getContentInsetRight() { return mContentInsets.getRight(); } private void ensureNavButtonView() { if (mNavButtonView == null) { mNavButtonView = new ImageButton(getContext(), null, 0, mNavButtonStyle); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = Gravity.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); mNavButtonView.setLayoutParams(lp); } } private void ensureCollapseButtonView() { if (mCollapseButtonView == null) { mCollapseButtonView = new ImageButton(getContext(), null, 0, mNavButtonStyle); mCollapseButtonView.setImageDrawable(mCollapseIcon); mCollapseButtonView.setContentDescription(mCollapseDescription); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = Gravity.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); lp.mViewType = LayoutParams.EXPANDED; mCollapseButtonView.setLayoutParams(lp); mCollapseButtonView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { collapseActionView(); } }); } } private void addSystemView(View v) { final ViewGroup.LayoutParams vlp = v.getLayoutParams(); final LayoutParams lp; if (vlp == null) { lp = generateDefaultLayoutParams(); } else if (!checkLayoutParams(vlp)) { lp = generateLayoutParams(vlp); } else { lp = (LayoutParams) vlp; } lp.mViewType = LayoutParams.SYSTEM; addView(v, lp); } @Override protected Parcelable onSaveInstanceState() { SavedState state = new SavedState(super.onSaveInstanceState()); if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) { state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId(); } state.isOverflowOpen = isOverflowMenuShowing(); return state; } @Override protected void onRestoreInstanceState(Parcelable state) { final SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); final Menu menu = mMenuView != null ? mMenuView.peekMenu() : null; if (ss.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && menu != null) { final MenuItem item = menu.findItem(ss.expandedMenuItemId); if (item != null) { item.expandActionView(); } } if (ss.isOverflowOpen) { postShowOverflowMenu(); } } private void postShowOverflowMenu() { removeCallbacks(mShowOverflowMenuRunnable); post(mShowOverflowMenuRunnable); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); removeCallbacks(mShowOverflowMenuRunnable); } @Override public boolean onTouchEvent(MotionEvent ev) { // Toolbars always eat touch events, but should still respect the touch event dispatch // contract. If the normal View implementation doesn't want the events, we'll just silently // eat the rest of the gesture without reporting the events to the default implementation // since that's what it expects. final int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { mEatingTouch = false; } if (!mEatingTouch) { final boolean handled = super.onTouchEvent(ev); if (action == MotionEvent.ACTION_DOWN && !handled) { mEatingTouch = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mEatingTouch = false; } return true; } /** * @hide */ @Override public void addClickableRectsForAccessibility(Listtrue
if the event was handled, false
otherwise.
*/
public boolean onMenuItemClick(MenuItem item);
}
/**
* Layout information for child views of Toolbars.
*
* Toolbar.LayoutParams extends ActionBar.LayoutParams for compatibility with existing * ActionBar API. See {@link android.app.Activity#setActionBar(Toolbar) Activity.setActionBar} * for more info on how to use a Toolbar as your Activity's ActionBar.
* * @attr ref android.R.styleable#Toolbar_LayoutParams_layout_gravity */ public static class LayoutParams extends ActionBar.LayoutParams { static final int CUSTOM = 0; static final int SYSTEM = 1; static final int EXPANDED = 2; int mViewType = CUSTOM; public LayoutParams(@NonNull Context c, AttributeSet attrs) { super(c, attrs); } public LayoutParams(int width, int height) { super(width, height); this.gravity = Gravity.CENTER_VERTICAL | Gravity.START; } public LayoutParams(int width, int height, int gravity) { super(width, height); this.gravity = gravity; } public LayoutParams(int gravity) { this(WRAP_CONTENT, MATCH_PARENT, gravity); } public LayoutParams(LayoutParams source) { super(source); mViewType = source.mViewType; } public LayoutParams(ActionBar.LayoutParams source) { super(source); } public LayoutParams(MarginLayoutParams source) { super(source); // ActionBar.LayoutParams doesn't have a MarginLayoutParams constructor. // Fake it here and copy over the relevant data. copyMarginsFrom(source); } public LayoutParams(ViewGroup.LayoutParams source) { super(source); } } static class SavedState extends BaseSavedState { public int expandedMenuItemId; public boolean isOverflowOpen; public SavedState(Parcel source) { super(source); expandedMenuItemId = source.readInt(); isOverflowOpen = source.readInt() != 0; } public SavedState(Parcelable superState) { super(superState); } @Override public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeInt(expandedMenuItemId); out.writeInt(isOverflowOpen ? 1 : 0); } public static final Creator