我需要找出当用户触摸Android.Webkit.WebView
的内容时点击了哪个元素,这与HTML元素的类型无关。
到目前为止,我的方法是使用Touch事件并执行类似的命中测试:
private void WebView_Touch(object sender, View.TouchEventArgs e)
{
var hitTest = webView.GetHitTestResult();
var type = hitTest.Type;
var element = hitTest.Extra;
// Determine what todo based on type and element
}
但是,当我在<button>
元素上单击时,会触发该事件,但命中测试不会产生任何结果,即type和element为空。也许命中测试尚未完成?我需要拨打GetHitRect
吗?
答案 0 :(得分:1)
我们可以根据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