在 Android 中禁用轨迹球点击
我在实现自定义进度对话框时遇到了一些困难。即使覆盖层拦截了触摸事件,用户仍然可以操作应该被禁用的轨迹球和单击元素。
有什么办法解决这个问题吗?
编辑:这是一个解决方案
//=====================================================================================
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了防止您的 Activity 在屏幕上时轨迹球执行任何操作,请将以下代码添加到您的 Activity 子类中。
我已经在 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.
I've tested this on a Google Nexus One phone and it works fine.
检查 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.
重写 onTrackballEvent() 不起作用。
尝试重写dispatchTrackballEvent(),什么都不做,只返回true;。
Override onTrackballEvent() does not work.
Try overriding dispatchTrackballEvent(), do nothing in it just return true;.