1.网页内的右键菜单
- publicbooleanonLongClick(Viewview){
- //获取点击的元素
- HitTestResultmResult=mWebView.getHitTestResult();
- finalinttype=mResult.getType();
- switch(type){
- caseHitTestResult.ANCHOR_TYPE:
- caseHitTestResult.SRC_ANCHOR_TYPE:
- //点击的是链接
- break;
- caseHitTestResult.IMAGE_TYPE:
- caseHitTestResult.IMAGE_ANCHOR_TYPE:
- caseHitTestResult.SRC_IMAGE_ANCHOR_TYPE:
- //点击的是图片
- break;
- default:
- //点击的是空白处
- break;
- }
- returntrue;
- }
根据是图片还是链接还是空白做判断
2.网页内的自由复制
转载请注明出处:http://blog.csdn.net/ethan_xue/article/details/7748075
- /**
- *网页里复制粘贴
- *@paramviewwebView
- *@authorethan
- */
- privatevoidemulateShiftHeld(KeyEvent.Callbackview)
- {
- try
- {
- KeyEventshiftPressEvent=newKeyEvent(0,0,KeyEvent.ACTION_DOWN,
- KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
- shiftPressEvent.dispatch(view);
- }catch(Exceptione)
- {
- }
- }
3.出错界面
webkit自带的出错界面不够霸气,于是改为自己做的出错界面
- newWebViewClient()
- ...此为背景
- @Override
- publicvoidonReceivedError(WebViewview,interrorCode,
- Stringdescription,StringfailingUrl){
- view.stopLoading();
- view.clearView();
- //显示出错界面
- mWebView.loadUrl("file:///android_asset/error.html");
- }
4.点外部链接调用自己的浏览器
在manifest.xml里主activity加入intent
- <pstyle="color:rgb(51,51,51);font-family:Arial;font-size:16px;line-height:25px;text-align:left;"><!--FortheseschemeswerenotparticularMIMEtypehasbeen
- supplied,weareagoodcandidate.-->
- <intent-filter>
- <actionandroid:name="android.intent.action.VIEW"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- <categoryandroid:name="android.intent.category.BROWSABLE"/>
- <dataandroid:scheme="http"/>
- <dataandroid:scheme="https"/>
- <dataandroid:scheme="about"/>
- <dataandroid:scheme="javascript"/>
- </intent-filter>
- <!--FortheseschemeswhereanyoftheseparticularMIMEtypes
- havebeensupplied,weareagoodcandidate.-->
- <intent-filter>
- <actionandroid:name="android.intent.action.VIEW"/>
- <categoryandroid:name="android.intent.category.BROWSABLE"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- <dataandroid:scheme="http"/>
- <dataandroid:scheme="https"/>
- <dataandroid:scheme="inline"/>
- <dataandroid:mimeType="text/html"/>
- <dataandroid:mimeType="text/plain"/>
- <dataandroid:mimeType="application/xhtml+xml"/>
- <dataandroid:mimeType="application/vnd.wap.xhtml+xml"/>
- </intent-filter>
- <actionandroid:name="android.intent.action.VIEW"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- <categoryandroid:name="android.intent.category.BROWSABLE"/>
- <dataandroid:scheme="file"/>
- </intent-filter></p>
外部调用就ok了,连file文件都能调用,若自己调用的话