我正在尝试让我的应用程序可用于盲人。在RecyclerView中点击子项时,它会突出显示,而在双击时,它会打开子项的类别。 基本上,必须双击才能执行点击操作。 我希望TalkBack通过Usage Hints来说明这一点。尝试使用[RecyclerViewAccessibilityDelegate] [1]
[1]:https://developer.android.com/reference/android/support/v7/widget/RecyclerViewAccessibilityDelegate,但无济于事。我成功地为单个ImageButton定制了使用提示,但在使用RecyclerView时却做错了。
这是我的MainActivity.java
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_levelx_layout);
..
..
initializeLayoutViews();
initializeViewListeners();
...
}
private void initializeLayoutViews()
{
...
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mRecyclerView.setAdapter(new MainActivityAdapter(this));
mRecyclerView.setVerticalScrollBarEnabled(true);
mRecyclerView.setScrollbarFadingEnabled(false);
mRecyclerView.requestFocus();
}
private void initializeViewListeners()
{
initRecyclerViewListeners();
}
private void initRecyclerViewListeners() {
mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, mRecyclerView, new RecyclerTouchListener.ClickListener()
{
@Override
public void onClick(final View view, final int position)
{
ViewCompat.setAccessibilityDelegate(mRecyclerView, new TalkbackHints_RecyclerView(mRecyclerView));
LinearLayout menuItemLinearLayout = view.findViewById(R.id.linearlayout_icon1);
menuItemLinearLayout.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
tappedCategoryItemEvent(view, v, position);
}
});
}
@Override
public void onLongClick(View view, int position) {
}
}));
mRecyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener()
{
@Override
public void onChildViewAttachedToWindow(View view)
{
mRecyclerItemsViewList.set(mRecyclerView.getChildLayoutPosition(view), view);
if (mRecyclerItemsViewList.contains(view) && mSelectedItemAdapterPos > -1 &&
mRecyclerView.getChildLayoutPosition(view) == mSelectedItemAdapterPos)
setMenuImageBorder(view, true);
}
@Override
public void onChildViewDetachedFromWindow(View view) {
setMenuImageBorder(view, false);
mRecyclerItemsViewList.set(mRecyclerView.getChildLayoutPosition(view), null);
}
});
}}
和TalkBackHints_RecyclerView.java:
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerViewAccessibilityDelegate;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
public class TalkbackHints_RecyclerView extends RecyclerViewAccessibilityDelegate
{
public TalkbackHints_RecyclerView(RecyclerView recyclerView) {
super(recyclerView);
}
@Override
public void onInitializeAccessibilityNodeInfo(View host,
AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
//RecyclerViewAccessibilityDelegate.ItemDelegate();
AccessibilityNodeInfoCompat.AccessibilityActionCompat intoCategory = new
AccessibilityNodeInfoCompat.AccessibilityActionCompat(
AccessibilityNodeInfo.ACTION_CLICK, "select. Double tap again to " +
"enter this category");
info.addAction(intoCategory);
}
}
请告诉我哪里出错了。