Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set contentDescription for ActionBar's up button

I'm trying to customize the "Navigate up" default contentDescription that is associated with the up button of the ActionBar (I'm using ActionBarSherlock).

From ActionBarView's source:

public void setHomeButtonEnabled(boolean enable) {
    mHomeLayout.setEnabled(enable);
    mHomeLayout.setFocusable(enable);
    // Make sure the home button has an accurate content description for accessibility.
    if (!enable) {
        mHomeLayout.setContentDescription(null);
    } else if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
        mHomeLayout.setContentDescription(mContext.getResources().getText(
                R.string.abs__action_bar_up_description));
    } else {
        mHomeLayout.setContentDescription(mContext.getResources().getText(
                R.string.abs__action_bar_home_description));
    }
}

so the key would be how to get a reference to mHomeLayout. getWindow().getDecorView().findViewById(android.R.id.home) is not working, as it's returning an ImageView.

How could I do?

Thanks ;)

like image 710
Venator85 Avatar asked May 21 '13 10:05

Venator85


2 Answers

In xml, use "navigationContentDescription"

<androidx.appcompat.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:layout_alignParentTop="true"
    app:navigationContentDescription="@string/back"/>
like image 124
Shroud Avatar answered Nov 03 '22 00:11

Shroud


layout

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    app:layout_scrollFlags="scroll|enterAlways">

</android.support.v7.widget.Toolbar>

code

public Toolbar toolbar;
...
setContentView(layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(layoutTitle);
setSupportActionBar(toolbar);
...
getSupportActionBar().setHomeActionContentDescription("Go Back To XYZ Screen");
like image 36
baybora.oren Avatar answered Nov 03 '22 01:11

baybora.oren