diff options
| -rw-r--r-- | core/java/android/widget/Toolbar.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java index ba2d5b8..1ce19ce 100644 --- a/core/java/android/widget/Toolbar.java +++ b/core/java/android/widget/Toolbar.java @@ -33,6 +33,7 @@ import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -132,6 +133,8 @@ public class Toolbar extends ViewGroup { private int mTitleTextColor; private int mSubtitleTextColor; + private boolean mEatingTouch; + // Clear me after use. private final ArrayList<View> mTempViews = new ArrayList<View>(); @@ -1061,6 +1064,32 @@ public class Toolbar extends ViewGroup { removeCallbacks(mShowOverflowMenuRunnable); } + @Override + public boolean onTouchEvent(MotionEvent ev) { + // Toolbars always eat touch events, but should still respect the touch event dispatch + // contract. If the normal View implementation doesn't want the events, we'll just silently + // eat the rest of the gesture without reporting the events to the default implementation + // since that's what it expects. + + final int action = ev.getActionMasked(); + if (action == MotionEvent.ACTION_DOWN) { + mEatingTouch = false; + } + + if (!mEatingTouch) { + final boolean handled = super.onTouchEvent(ev); + if (action == MotionEvent.ACTION_DOWN && !handled) { + mEatingTouch = true; + } + } + + if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { + mEatingTouch = false; + } + + return true; + } + /** * @hide */ |
