android – 为ActionBar的up按钮设置contentDescription

前端之家收集整理的这篇文章主要介绍了android – 为ActionBar的up按钮设置contentDescription前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试自定义与ActionBar的向上按钮相关联的“向上导航”默认contentDescription(我正在使用ActionBarSherlock).

来自ActionBarView的来源:

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));
    }
}

所以关键是如何获得对mHomeLayout的引用. getWindow().getDecorView().findViewById(android.R.id.home)无效,因为它返回了一个ImageView.

我该怎么办?

谢谢 原文链接:https://www.f2er.com/android/309072.html

猜你在找的Android相关文章