package android.widget;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.ActionBar;
import android.content.Context;
import android.content.res.TypedArray;
}
/**
- * Set the icon to use for the toolbar's navigation button.
- *
- * <p>The navigation button appears at the start of the toolbar if present. Setting an icon
- * will make the navigation button visible.</p>
- *
- * <p>If you use a navigation icon you should also set a description for its action using
- * {@link #setNavigationDescription(int)}. This is used for accessibility and tooltips.</p>
- *
- * @param resId Resource ID of a drawable to set
- */
- public void setNavigationIcon(int resId) {
- setNavigationIcon(getContext().getDrawable(resId));
- }
-
- /**
* 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
*/
+ @Nullable
public CharSequence getNavigationContentDescription() {
return mNavButtonView != null ? mNavButtonView.getContentDescription() : null;
}
* 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
+ * @param resId Resource ID of a content description string to set, or 0 to
+ * clear the description
*/
- public void setNavigationContentDescription(CharSequence description) {
- ensureNavButtonView();
- mNavButtonView.setContentDescription(description);
+ public void setNavigationContentDescription(int resId) {
+ setNavigationContentDescription(resId != 0 ? getContext().getText(resId) : null);
}
/**
* 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
+ * @param description Content description to set, or <code>null</code> to
+ * clear the content description
*/
- public void setNavigationContentDescription(int resId) {
- ensureNavButtonView();
- mNavButtonView.setContentDescription(resId != 0 ? getContext().getText(resId) : null);
+ 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.
+ *
+ * <p>The navigation button appears at the start of the toolbar if present. Setting an icon
+ * will make the navigation button visible.</p>
+ *
+ * <p>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.</p>
+ *
+ * @param resId Resource ID of a drawable to set
+ */
+ public void setNavigationIcon(int resId) {
+ setNavigationIcon(getContext().getDrawable(resId));
}
/**
* will make the navigation button visible.</p>
*
* <p>If you use a navigation icon you should also set a description for its action using
- * {@link #setNavigationDescription(int)}. This is used for accessibility and tooltips.</p>
+ * {@link #setNavigationContentDescription(int)}. This is used for accessibility and
+ * tooltips.</p>
*
- * @param icon Drawable to set
+ * @param icon Drawable to set, may be null to clear the icon
*/
- public void setNavigationIcon(Drawable icon) {
+ public void setNavigationIcon(@Nullable Drawable icon) {
if (icon != null) {
ensureNavButtonView();
if (mNavButtonView.getParent() == null) {
*
* @return The navigation icon drawable
*/
+ @Nullable
public Drawable getNavigationIcon() {
return mNavButtonView != null ? mNavButtonView.getDrawable() : null;
}
/**
- * Set a description for the navigation button.
- *
- * <p>This description string is used for accessibility, tooltips and other facilities
- * to improve discoverability.</p>
- *
- * @param resId Resource ID of a string to set
- */
- public void setNavigationDescription(int resId) {
- setNavigationDescription(getContext().getText(resId));
- }
-
- /**
- * Set a description for the navigation button.
- *
- * <p>This description string is used for accessibility, tooltips and other facilities
- * to improve discoverability.</p>
- *
- * @param description String to set as the description
- */
- public void setNavigationDescription(CharSequence description) {
- if (!TextUtils.isEmpty(description)) {
- ensureNavButtonView();
- }
- if (mNavButtonView != null) {
- mNavButtonView.setContentDescription(description);
- }
- }
-
- /**
* Set a listener to respond to navigation events.
*
* <p>This listener will be called whenever the user clicks the navigation button