Often see others in the app WebView long press the image can display large image, click the number can directly find the phone, then how this is achieved?
WebView's Gethittestresult () function can get the type of the clicked page element, and then we will do the corresponding processing according to the type.
1 hittestresult result = ((WebView) v). Gethittestresult ()
Hittestresult class
Method |
Describe |
GetType () |
Gets the type of target selected, which can be a picture, hyperlink, mail, phone, etc. |
Getextra () |
Get additional information |
Specific use:
1Mwebview.setonlongclicklistener (NewOnlongclicklistener () {2 3 Public BooleanOnlongclick (View v) {4Hittestresult result =( (WebView) v). Gethittestresult ();5 if(NULL==result)6 return false;7 intType =Result.gettype ();8 Switch(type) {9 CaseWebView.HitTestResult.EDIT_TEXT_TYPE://selected type of textTen Break; One CaseWebView.HitTestResult.PHONE_TYPE://Processing Dialing A Break; - CaseWebView.HitTestResult.EMAIL_TYPE://Handling Email - Break; the CaseWebView.HitTestResult.GEO_TYPE://Map Type - Break; - CaseWebView.HitTestResult.SRC_ANCHOR_TYPE://Hypertext Links - Break; + CaseWebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE://types of pictures with links - CaseWebView.HitTestResult.IMAGE_TYPE://working with long-pressed picture menu items} + return true; A CaseWebView.HitTestResult.UNKNOWN_TYPE://Unknown at Break; - } - return false; - } -});
All enum type definitions are as follows:
Type name |
Significance |
WebView.HitTestResult.UNKNOWN_TYPE |
Unknown type |
WebView.HitTestResult.PHONE_TYPE |
Phone type |
WebView.HitTestResult.EMAIL_TYPE |
e-Mail type |
WebView.HitTestResult.GEO_TYPE |
Map type |
WebView.HitTestResult.SRC_ANCHOR_TYPE |
Type of hyperlink |
WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE |
Types of pictures with links |
WebView.HitTestResult.IMAGE_TYPE |
Simple type of picture |
WebView.HitTestResult.EDIT_TEXT_TYPE |
Selected type of text |
Get the click element of Android WebView