Android 使用 TalkBack 迭代 RecycleView 的隐藏项
Android iterate RecycleView's hidden items with TalkBack
我有一个 recycleview,里面有 10 多个项目。因为它有10多个项目,所以一次只显示4个项目。 TalkBack 出现问题,我想通过拖动 left/right 操作在列表中进行迭代,但在 4.item 之后焦点转到布局上的另一个视图组件。我如何使用 Talkback 迭代 recycleview 的所有项目?
编辑:
我像这样使用自己的辅助功能委托:
mRecyclerView.setAccessibilityDelegate(mAccessibilityDelegate);
public class AccessibilityDelegate extends View.AccessibilityDelegate {
private Assistant mAssistant;
public AccessibilityDelegate(Assistant assistant)
{
mAssistant = assistant;
}
@Override
public void sendAccessibilityEvent(View host, int eventType) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
super.sendAccessibilityEvent(host, eventType);
}
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
return super.performAccessibilityAction(host, action, args);
}
return false;
}
@Override
public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
super.sendAccessibilityEventUnchecked(host, event);
}
@Override
public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
return super.dispatchPopulateAccessibilityEvent(host, event);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
return super.onRequestSendAccessibilityEvent(host, child, event);
}
@Override
public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) {
return super.getAccessibilityNodeProvider(host);
}
}
经过几次试验,我发现了问题。
要覆盖 RecycleView 的辅助功能,请扩展 RecyclerViewAccessibilityDelegate。
//mRecyclerView.setAccessibilityDelegate(mAccessibilityDelegate);
RVAccessibilityDelegate rvAccessibilityDelegate = new RVAccessibilityDelegate(mRecyclerView, mAssistant);
mRecyclerView.setAccessibilityDelegateCompat(rvAccessibilityDelegate);
此外,如果您想禁用像 "showing item 1 of 6" 这样的公告,只需注释掉 super.sendAccessibilityEventUnchecked(host, event)
public class RVAccessibilityDelegate extends RecyclerViewAccessibilityDelegate {
private Assistant mAssistant;
public RVAccessibilityDelegate(RecyclerView recyclerView, Assistant assistant) {
super(recyclerView);
mAssistant = assistant;
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
return super.performAccessibilityAction(host, action, args);
}
return false;
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void sendAccessibilityEvent(View host, int eventType) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
super.sendAccessibilityEvent(host, eventType);
}
}
@Override
public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
//super.sendAccessibilityEventUnchecked(host, event);
}
@Override
public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
return super.dispatchPopulateAccessibilityEvent(host, event);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
}
@Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
return super.onRequestSendAccessibilityEvent(host, child, event);
}
@Override
public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host) {
return super.getAccessibilityNodeProvider(host);
}
}
我有一个 recycleview,里面有 10 多个项目。因为它有10多个项目,所以一次只显示4个项目。 TalkBack 出现问题,我想通过拖动 left/right 操作在列表中进行迭代,但在 4.item 之后焦点转到布局上的另一个视图组件。我如何使用 Talkback 迭代 recycleview 的所有项目?
编辑: 我像这样使用自己的辅助功能委托:
mRecyclerView.setAccessibilityDelegate(mAccessibilityDelegate);
public class AccessibilityDelegate extends View.AccessibilityDelegate {
private Assistant mAssistant;
public AccessibilityDelegate(Assistant assistant)
{
mAssistant = assistant;
}
@Override
public void sendAccessibilityEvent(View host, int eventType) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
super.sendAccessibilityEvent(host, eventType);
}
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
return super.performAccessibilityAction(host, action, args);
}
return false;
}
@Override
public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
super.sendAccessibilityEventUnchecked(host, event);
}
@Override
public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
return super.dispatchPopulateAccessibilityEvent(host, event);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
return super.onRequestSendAccessibilityEvent(host, child, event);
}
@Override
public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) {
return super.getAccessibilityNodeProvider(host);
}
}
经过几次试验,我发现了问题。
要覆盖 RecycleView 的辅助功能,请扩展 RecyclerViewAccessibilityDelegate。
//mRecyclerView.setAccessibilityDelegate(mAccessibilityDelegate);
RVAccessibilityDelegate rvAccessibilityDelegate = new RVAccessibilityDelegate(mRecyclerView, mAssistant);
mRecyclerView.setAccessibilityDelegateCompat(rvAccessibilityDelegate);
此外,如果您想禁用像 "showing item 1 of 6" 这样的公告,只需注释掉 super.sendAccessibilityEventUnchecked(host, event)
public class RVAccessibilityDelegate extends RecyclerViewAccessibilityDelegate {
private Assistant mAssistant;
public RVAccessibilityDelegate(RecyclerView recyclerView, Assistant assistant) {
super(recyclerView);
mAssistant = assistant;
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
return super.performAccessibilityAction(host, action, args);
}
return false;
}
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
}
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
}
@Override
public void sendAccessibilityEvent(View host, int eventType) {
if(!mAssistant.isSpeaking() && mAssistant.isRecognizerAvailable())
{
super.sendAccessibilityEvent(host, eventType);
}
}
@Override
public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
//super.sendAccessibilityEventUnchecked(host, event);
}
@Override
public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
return super.dispatchPopulateAccessibilityEvent(host, event);
}
@Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
}
@Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
return super.onRequestSendAccessibilityEvent(host, child, event);
}
@Override
public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host) {
return super.getAccessibilityNodeProvider(host);
}
}