Android辅助功能识别标题

时间:2016-10-24 05:42:03

标签: android accessibility heading android-accessibility

我有最新版本的Talkback,并宣布“我的顶级文字标题”。 Android本机行为为我的顶级元素添加了“标题”。我找不到一种方法来切换ON / OFF标题声明。是否有API来控制其行为。在之前版本的Talkback版本中,它并没有单独宣布“标题”。

4 个答案:

答案 0 :(得分:1)

如果您仅支持API级别23及更高版本,则只需执行以下操作即可。

textView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
  @Override
  public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    //blanked to prevent talkback from announcing class/type
    info.setClassName("");
  }
});

答案 1 :(得分:1)

我通过在

中将标题传递为false来解决这个问题
AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain method.

        // set the heading attribute to false so that heading is not announced in label  

info.setCollectionItemInfo(
    AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(glp.getSpanIndex(),
 glp.getSpanSize(), spanGroupIndex, 1, false, false));

public static CollectionItemInfoCompat obtain(int rowIndex, 
int rowSpan, int columnIndex, int columnSpan,
boolean heading, boolean selected)

答案 2 :(得分:1)

您可以启用或禁用API 19+上任何View的“标题”可访问性属性:

ViewCompat.setAccessibilityDelegate(headingView, new AccessibilityDelegateCompat() {
  @Override
  public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
    super.onInitializeAccessibilityNodeInfo(host, info);
    info.setHeading(true); // false to mark a view as not a heading
  }
});

如果您拥有minSdk 28,则可以直接在XML中直接进行设置:

android:accessibilityHeading="false"

答案 3 :(得分:1)

在API 19+上添加一个简单的方法:

ViewCompat.setAccessibilityHeading(headingView, false);

https://developer.android.com/reference/androidx/core/view/ViewCompat#setAccessibilityHeading(android.view.View,%20boolean)