在 Android 中禁用轨迹球点击

发布于 2024-09-13 21:40:55 字数 1019 浏览 8 评论 0原文

我在实现自定义进度对话框时遇到了一些困难。即使覆盖层拦截了触摸事件,用户仍然可以操作应该被禁用的轨迹球和单击元素。

有什么办法解决这个问题吗?

编辑:这是一个解决方案

//=====================================================================================
protected void showProgressIndicator()
{
    progressIndicator_.show();
}

//=====================================================================================
@Override
public boolean onTrackballEvent(MotionEvent event)
{
    return progressIndicator_.getVisibility() == View.VISIBLE;
}

//=====================================================================================
protected void hideProgressIndicator()
{
    progressIndicator_.hide();
}

An then in show 方法

//=====================================================================================
public void show()
{
    setVisibility(VISIBLE);
    if (animationHandler_ != null)
        return;

    animationHandler_ = new Handler();
    animationHandler_.post(animateTask_);
    requestFocus();
}

I've run into some difficulties with implementing a custom progress dialog. Even though an overlay intercepts touch events the user can still operate the trackball and click elements that are supposed to be disabled.

Is there any way around this?

Edit: here's a solution

//=====================================================================================
protected void showProgressIndicator()
{
    progressIndicator_.show();
}

//=====================================================================================
@Override
public boolean onTrackballEvent(MotionEvent event)
{
    return progressIndicator_.getVisibility() == View.VISIBLE;
}

//=====================================================================================
protected void hideProgressIndicator()
{
    progressIndicator_.hide();
}

An then in show method

//=====================================================================================
public void show()
{
    setVisibility(VISIBLE);
    if (animationHandler_ != null)
        return;

    animationHandler_ = new Handler();
    animationHandler_.post(animateTask_);
    requestFocus();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日记撕了你也走了 2024-09-20 21:40:55

为了防止您的 Activity 在屏幕上时轨迹球执行任何操作,请将以下代码添加到您的 Activity 子类中。

@Override 
public boolean dispatchTrackballEvent(android.view.MotionEvent ev) {
  return true;
};

我已经在 Google Nexus One 手机上对此进行了测试,效果很好。

In order to prevent your trackball doing anything while your activity is on screen, add the following code to your Activity subclass.

@Override 
public boolean dispatchTrackballEvent(android.view.MotionEvent ev) {
  return true;
};

I've tested this on a Google Nexus One phone and it works fine.

夜还是长夜 2024-09-20 21:40:55

检查 onTrackballEvent() 方法。然后尝试在方法中直接返回true而不做任何事情。这应该立即终止该事件。

Check the onTrackballEvent() method. Then try to directly returning true in the method without doing anything in it. This should kill the event right away.

丑丑阿 2024-09-20 21:40:55

重写 onTrackballEvent() 不起作用。
尝试重写dispatchTrackballEvent(),什么都不做,只返回true;。

Override onTrackballEvent() does not work.
Try overriding dispatchTrackballEvent(), do nothing in it just return true;.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文