1

我使用以下样式并定义了一个模态活动:

<style name="Theme.TransparentD0" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/semi_transparentD0</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

如何检查用户是否触摸了我的活动内部或外部?

4

1 回答 1

5
@Override
public boolean onTouchEvent(MotionEvent event) {

    final int width = getWindow().getDecorView().getWidth();
    final int height = getWindow().getDecorView().getHeight();
    final int x = (int) event.getX();
    final int y = (int) event.getY();

    if (x > 0 && y > 0 && x < width && y < height)
    {
        Log.i("onTouchEvent", "Inside");
    }
    else
    {
        Log.i("onTouchEvent", "Outside");
    }
    return super.onTouchEvent(event);
}
于 2012-12-25T08:07:52.900 回答