Pregunta

I'm currently trying to build an Android app with Xamarin Studio (aka monodroid). My problem is as follows:

In my Activity's OnCreate I call

this.RequestWindowFeature(WindowFeatures.ActionBar);
this.RequestWindowFeature(WindowFeatures.ActionModeOverlay);

Also, I added this override to the Activity:

public override Boolean OnTouchEvent(MotionEvent e)
{
    if (this.ActionBar.IsShowing)
    {
        this.ActionBar.Hide();
    }
    else
    {
        this.ActionBar.Show();
    }

    return base.OnTouchEvent(e);
}

This, however, doesn't work as I expect it to: When I first tap on the Activity, the bar is hidden. The next tap shows it, but it doesn't even fully slide into view before it retreats again. Also, it seems to "cram" the contents of the Activity, which it shouldn't do since I added WindowFeatures.ActionModeOverlay.
What am I missing?

EDIT: I am certain that the method itself is only triggered once per touch (I logged a counter to diagnose).
Also, I don't show()/hide() the ActionBar anywhere else.

EDIT 2: I was certain, but probably messed up the diagnostic approach. :/
After adding

if (e.Action == MotionEventActions.Cancel
    || e.Action == MotionEventActions.Up)
{
    return base.OnTouchEvent(e);
}

it behaves as expected.

¿Fue útil?

Solución

Motion Event is catching an event when you are releasing a touch, you need to filter the event further using e.Action for touch down and release events. I think down is triggering show, and release is hiding it again

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top