Ven*_*r85 8 android accessibility actionbarsherlock android-actionbar
我正在尝试自定义与" 我正在使用ActionBarSherlock" contentDescription的向上按钮相关联的"向上导航"默认值ActionBar.
从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));
}
}
Run Code Online (Sandbox Code Playgroud)
所以关键是如何获得参考mHomeLayout.getWindow().getDecorView().findViewById(android.R.id.home)不起作用,因为它返回一个ImageView.
我该怎么办?
谢谢 ;)
小智 12
在 xml 中,使用“navigationContentDescription”
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_alignParentTop="true"
app:navigationContentDescription="@string/back"/>
Run Code Online (Sandbox Code Playgroud)
布局
<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>
Run Code Online (Sandbox Code Playgroud)
码
public Toolbar toolbar;
...
setContentView(layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(layoutTitle);
setSupportActionBar(toolbar);
...
getSupportActionBar().setHomeActionContentDescription("Go Back To XYZ Screen");
Run Code Online (Sandbox Code Playgroud)
这里我可以如何做你在之前的项目中需要的事情:
((View) getWindow().getDecorView().findViewById(android.R.id.home).getParent().getParent()).setContentDescription("blablabla");
Run Code Online (Sandbox Code Playgroud)
使用 viewHierarchy 插件可以帮助我理解 ActionBar 布局是如何构建的。
| 归档时间: |
|
| 查看次数: |
5201 次 |
| 最近记录: |