Disable trackball click in Android

北战南征 提交于 2019-12-29 01:53:08

问题


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

回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3423948/disable-trackball-click-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!