本文介绍了Android的 - 覆盖话语提示手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序中使用话语,但仍需要一些活动来表现不同。例如,输入特定活动我想选择一个按钮,当手指抬起时,从该按钮(触发一个按钮点击)。话语提示只允许双击选择按钮。

I want to use TalkBack within my app, but still want some activities to behave differently. For example, when entering a specific activity I want to select a button (trigger a button click) when lifting finger up from that button. TalkBack enables only double-click to select a button.

我如何覆盖话语提示手势?

How can I "override" TalkBack gestures?

谢谢!

推荐答案

您可以对HOVER_EXIT点击动作,但你需要从预期正常的双击动作做了一些工作,以prevent话语提示。电话拨号的<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/4.3_r2.1/com/android/dialer/dialpad/DialpadImageButton.java?av=f\"相对=nofollow> DialPadImageButton 提供的这种行为一个很好的例子。以下是code的一些相关的部分从那个类:

You can perform a click action on HOVER_EXIT, but you'll need to do some work to prevent TalkBack from expecting the normal double-click action. The phone dialer's DialPadImageButton provides a good example of this behavior. Here are some relevant portions of code from that class:

@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);
}

这篇关于Android的 - 覆盖话语提示手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:28