5

Tôi đang cố gắng tùy chỉnh "Điều hướng" mặc định contentDescription được liên kết với nút lên của ActionBar (Tôi đang sử dụng ActionBarSherlock).Đặt contentDescription cho nút ActionBar's up

Từ nguồn ActionBarView 's:

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

để chìa khóa sẽ là làm thế nào để có được một tài liệu tham khảo để mHomeLayout. getWindow().getDecorView().findViewById(android.R.id.home) không hoạt động vì nó trả về một ImageView.

Tôi làm cách nào?

cám ơn;)

Trả lời

4

đây làm thế nào tôi có thể làm những gì bạn cần trong một dự án theo thời gian:

((View) getWindow().getDecorView().findViewById(android.R.id.home).getParent().getParent()).setContentDescription("blablabla"); 

Sử dụng viewHierarchy Plugin giúp tôi hiểu thế nào ActionBar bố trí là xây dựng.

0

Trong trường hợp ai đó cần thiết lập của ActionBar nhà nút của nội dung mô tả cho UIAutomator, sử dụng

((View) getWindow().getDecorView().findViewById(android.R.id.home).getParent()).setContentDescription("MANUALLYSET-home-up"); 

và truy cập vào xem trong UIAutomatorTestCase bạn sử dụng

new UiObject(new UiSelector().description("MANUALLYSET-home-up").className("android.widget.FrameLayout")); 

Đối với một số lý do khác * .getParent() không hoạt động, thay vào đó, Android sử dụng một số giá trị mô tả nội dung được tạo tự động cho cha mẹ có thể khác trong một số phiên bản Android (ví dụ: "app_name, Đóng ngăn điều hướng" trên KITKAT và "app_name, Điều hướng" trên JEL LYBEAN). Truy cập vào con của nó hoạt động quá, may mắn thay.

Kind coi

4

bố trí

<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> 

đang

public Toolbar toolbar; 
... 
setContentView(layout); 
toolbar = (Toolbar) findViewById(R.id.toolbar); 
toolbar.setTitle(layoutTitle); 
setSupportActionBar(toolbar); 
... 
getSupportActionBar().setHomeActionContentDescription("Go Back To XYZ Screen"); 
Các vấn đề liên quan