首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -覆盖TalkBack手势

Android -覆盖TalkBack手势
EN

Stack Overflow用户
提问于 2013-06-10 14:48:08
回答 1查看 2.5K关注 0票数 3

我想在我的应用程序中使用TalkBack,但仍然希望一些活动的行为有所不同。例如,当输入一个特定的活动时,我想要选择一个按钮(触发一个按钮点击),当我从该按钮上抬起手指时。TalkBack仅支持双击以选择按钮。

如何“覆盖”TalkBack手势?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-08-21 15:21:22

您可以在HOVER_EXIT上执行单击操作,但您需要做一些工作来防止TalkBack期望正常的双击操作。电话拨号器的DialPadImageButton就是一个很好的例子。下面是该类的一些相关代码部分:

代码语言:javascript
复制
@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);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17018252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档