[英]Android - Override TalkBack gestures
我想在我的应用程序中使用TalkBack,但仍希望某些活动表现不同。 例如,当输入特定活动时,我想从该按钮抬起手指时选择一个按钮(触发按钮单击)。 TalkBack只允许双击选择按钮。
我如何“覆盖”TalkBack手势?
谢谢!
您可以对HOVER_EXIT执行单击操作,但是您需要做一些工作以防止TalkBack期望正常的双击操作。 电话拨号器的DialPadImageButton提供了这种行为的一个很好的例子。 以下是该类代码的一些相关部分:
@Override
public boolean onHoverEvent(MotionEvent event) {
// When touch exploration is turned on, lifting a finger while inside
// the button's hover target bounds should perform a click action.
if (mAccessibilityManager.isEnabled()
&& mAccessibilityManager.isTouchExplorationEnabled()) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
// Lift-to-type temporarily disables double-tap activation.
setClickable(false);
break;
case MotionEvent.ACTION_HOVER_EXIT:
if (mHoverBounds.contains((int) event.getX(), (int) event.getY())) {
simulateClickForAccessibility();
}
setClickable(true);
break;
}
}
return super.onHoverEvent(event);
}
/**
* When accessibility is on, simulate press and release to preserve the
* semantic meaning of performClick(). Required for Braille support.
*/
private void simulateClickForAccessibility() {
// Checking the press state prevents double activation.
if (isPressed()) {
return;
}
setPressed(true);
// Stay consistent with performClick() by sending the event after
// setting the pressed state but before performing the action.
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
setPressed(false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.