Google 致力于为黑人社区推动种族平等。查看具体举措

ExploreByTouchHelper

abstract class ExploreByTouchHelper : AccessibilityDelegateCompat
kotlin.Any
   ↳ androidx.core.view.AccessibilityDelegateCompat
   ↳ androidx.customview.widget.ExploreByTouchHelper

ExploreByTouchHelper is a utility class for implementing accessibility support in custom Views that represent a collection of View-like logical items. It extends AccessibilityNodeProviderCompat and simplifies many aspects of providing information to accessibility services and managing accessibility focus.

Clients should override abstract methods on this class and attach it to the host view using ViewCompat#setAccessibilityDelegate.

The host view should also override the events in the following code snippet so that the view's logical items are detected properly by the framework:

class MyCustomView extends View {
      private MyExploreByTouchHelper mExploreByTouchHelper;
 
      public MyCustomView(Context context, ...) {
          ...
          mExploreByTouchHelper = new MyExploreByTouchHelper(this);
          ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
      }
 
      @Override
      public boolean dispatchHoverEvent(MotionEvent event) {
        return mHelper.dispatchHoverEvent(this, event)
            || super.dispatchHoverEvent(event);
      }
 
      @Override
      public boolean dispatchKeyEvent(KeyEvent event) {
        return mHelper.dispatchKeyEvent(event)
            || super.dispatchKeyEvent(event);
      }
 
      @Override
      public void onFocusChanged(boolean gainFocus, int direction,
          Rect previouslyFocusedRect) {
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
        mHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
      }
  }
  

Summary

Constants
static Int

Virtual node identifier value for the host view's node.

static Int

Virtual node identifier value for invalid nodes.

Public constructors
<init>(@NonNull host: View)

Constructs a new helper that can expose a virtual view hierarchy for the specified host view.

Public methods
Boolean

Attempts to clear keyboard focus from a virtual view.

Boolean

Delegates hover events from the host view.

Boolean
dispatchKeyEvent(@NonNull event: KeyEvent)

Delegates key events from the host view.

Int

open AccessibilityNodeProviderCompat!

open Int

Returns the virtual view ID for the currently accessibility focused item.

Int

Unit

Notifies the accessibility framework that the properties of the parent view have changed.

Unit
invalidateVirtualView(virtualViewId: Int)

Notifies the accessibility framework that the properties of a particular item have changed.

Unit
invalidateVirtualView(virtualViewId: Int, changeTypes: Int)

Notifies the accessibility framework that the properties of a particular item have changed.

Unit
onFocusChanged(gainFocus: Boolean, direction: Int, @Nullable previouslyFocusedRect: Rect?)

Delegates focus changes from the host view.

open Unit

open Unit

Boolean

Attempts to give keyboard focus to a virtual view.

Boolean
sendEventForVirtualView(virtualViewId: Int, eventType: Int)

Populates an event of the specified type with information about an item and attempts to send it up through the view hierarchy.

Protected methods
abstract Int

Provides a mapping between view-relative coordinates and logical items.

abstract Unit

Populates a list with the view's visible items.

abstract Boolean
onPerformActionForVirtualView(virtualViewId: Int, action: Int, @Nullable arguments: Bundle?)

Performs the specified accessibility action on the item associated with the virtual view identifier.

open Unit

Populates an AccessibilityEvent with information about the host view.

open Unit
onPopulateEventForVirtualView(virtualViewId: Int, @NonNull event: AccessibilityEvent)

Populates an AccessibilityEvent with information about the specified item.

open Unit

Populates an AccessibilityNodeInfoCompat with information about the host view.

abstract Unit

Populates an AccessibilityNodeInfoCompat with information about the specified item.

open Unit
onVirtualViewKeyboardFocusChanged(virtualViewId: Int, hasFocus: Boolean)

Called when the focus state of a virtual view changes.

Inherited functions