监听WebView的各种点击事件
2015-05-04 15:32
281 查看
重写WebView,在WebView中设置接口,相当于自定义一个OnClickListener接口,然后使用的时候就可以调用setOnTouchScreenListener()方法,实现你想要的效果。
使用的时候:
import android.content.Context; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.webkit.WebView; public class MyWebView extends WebView { private OnTouchScreenListener onTouchScreenListener; public MyWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyWebView(Context context, AttributeSet attrs) { super(context, attrs); } public MyWebView(Context context) { super(context); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (onTouchScreenListener != null) onTouchScreenListener.onTouchScreen(); } if (event.getAction() == MotionEvent.ACTION_UP) { if (onTouchScreenListener != null) onTouchScreenListener.onReleaseScreen(); } return super.onTouchEvent(event); } public interface OnTouchScreenListener { void onTouchScreen(); void onReleaseScreen(); } public void setOnTouchScreenListener(OnTouchScreenListener onTouchScreenListener) { this.onTouchScreenListener = onTouchScreenListener; } }
使用的时候:
mWebView.setOnTouchScreenListener(new OnTouchScreenListener() { @Override public void onTouchScreen() { isFlowing = true; if (flowBottomLL.getVisibility() == View.GONE) { flowBottomLL.startAnimation(flowbottomLLAppearAS); flowBottomLL.setVisibility(View.VISIBLE); } } @Override public void onReleaseScreen() { isFlowing = false; if (flowBottomLL.getVisibility() == View.VISIBLE) { Message msg = handler.obtainMessage(1); currentTime = System.currentTimeMillis(); Bundle bundle = new Bundle(); bundle.putLong("currentTime", currentTime); msg.setData(bundle); handler.sendMessageDelayed(msg, 3000); } } });
相关文章推荐
- 关于webview的各种问题,webview中的点击事件,上传图片问题
- 在webview中如何监听页面的点击事件并跳转到指定的Activity?
- Android webview监听网页对话框点击事件
- Android 响应webview中图片的点击事件
- MVP+banner+banner点击事件+webview
- recyclerview点击事件 webview 多条目
- webView里面图片的点击事件
- android webview js交互, 响应webview中的图片点击事件
- Android中的WebView布局点击事件的方法
- 安卓中RecyclerView的简单使用和自定义RecyclerView的接口点击监听事件
- android webview js交互, 响应webview中的图片点击事件
- WebView加载网页以及处理里面的超链接点击事件
- IOS-监听UIAlertView按钮的点击事件
- webview长按事件js监听
- 监听tableview的点击事件
- iOS WebView 如何通过js获取网页中所有图片并加入点击事件,实现浏览图片的功能
- WebView的一些基础设置,避免获取不到点击事件
- 如何监听WebView显示事件
- 云飞的获取webview视频点击事件方法
- AlertDialog中使用自定义View,view中的Button如何设置点击事件监听