How to check if I have touched inside or outside of a modal Activity?

99封情书 提交于 2019-12-08 08:03:20

问题


I use the following style and defined a modal activity:

<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>

How to check if user has touched inside or outside of my Activity?


回答1:


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


来源:https://stackoverflow.com/questions/14028842/how-to-check-if-i-have-touched-inside-or-outside-of-a-modal-activity

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