我们可以根据Android API文档检测以下HTML元素.
int ANCHOR_TYPE HitTestResult for hitting a HTML::a tag
int EDIT_TEXT_TYPE HitTestResult for hitting an edit text area
int EMAIL_TYPE HitTestResult for hitting an email address
int GEO_TYPE HitTestResult for hitting a map address
int IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag which contains HTML::img
int IMAGE_TYPE HitTestResult for hitting an HTML::img tag
int PHONE_TYPE HitTestResult for hitting a phone number
int SRC_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http
int SRC_IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http + HTML::img
int UNKNOWN_TYPE Default HitTestResult, where the target is unknown
我想你将能够使用WebView的setOnTouchListener函数获取所有事件.
WebView具有名为HitTestResult的内部类.
HitTestResult类将帮助我们找到用户单击WebView时按下的HTML元素.
> getExtra():返回String. String具有由用户单击的HTML元素
> getType():返回整数.它用于标识用户单击的HTML元素.
你可以这样做:
wv.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
Log.i(TAG, "getExtra = "+ hr.getExtra() + " Type=" + hr.getType());
return false;
}
});