android浏览器开发小技巧集锦

android浏览器开发小技巧集锦本人和朋友们做了一段时间浏览器,将一些小技巧分享出来,先写一部分,慢慢写,同时也为我们的浏览器打打广告我们的浏览器将要上线,名叫沙发浏览1.网页内的右键菜单publicbooleanonLongClick(Viewview){ //获取点击的元素 HitTestResultmResult=mWebView.getHitTestResult(); fin

大家好,又见面了,我是你们的朋友全栈君。

本人和朋友们做了一段时间浏览器,将一些小技巧分享出来,先写一部分,慢慢写,同时也为我们的浏览器打打广告

我们的浏览器将要上线,名叫沙发浏览

1.网页内的右键菜单

android浏览器开发小技巧集锦

public boolean onLongClick(View view) {
		// 获取点击的元素
		HitTestResult mResult = mWebView.getHitTestResult();

		final int type = mResult.getType();
		switch (type) {
			case HitTestResult.ANCHOR_TYPE:
			case HitTestResult.SRC_ANCHOR_TYPE:
				//点击的是链接
				break;

			case HitTestResult.IMAGE_TYPE:
			case HitTestResult.IMAGE_ANCHOR_TYPE:
			case HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
				//点击的是图片
				break;

			default:
				//点击的是空白处
				break;
		}
		return true;
	}

根据是图片还是链接还是空白做判断

2.网页内的自由复制

转载请注明出处:http://blog.csdn.net/ethan_xue/article/details/7748075

android浏览器开发小技巧集锦

/**
	 * 网页里 复制粘贴
	 * @param view webView
	 * @author ethan
	 */
	private void emulateShiftHeld(KeyEvent.Callback view)
	{
		try
		{
			KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
					KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
			shiftPressEvent.dispatch(view);
		} catch (Exception e)
		{
		}
	}

3.出错界面

webkit自带的出错界面不够霸气,于是改为自己做的出错界面

new WebViewClient()
...此为背景
@Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			view.stopLoading();
			view.clearView();

			// 显示出错界面
			mWebView.loadUrl("file:///android_asset/error.html");
		}

4.点外部链接调用自己的浏览器

在manifest.xml里主activity加入intent

<!-- For these schemes were not particular MIME type has been                  supplied, we are a good candidate. -->             <intent-filter>                 <action android:name="android.intent.action.VIEW" />                 <category android:name="android.intent.category.DEFAULT" />                 <category android:name="android.intent.category.BROWSABLE" />                 <data android:scheme="http" />                 <data android:scheme="https" />                 <data android:scheme="about" />                 <data android:scheme="javascript" />             </intent-filter>             <!--  For these schemes where any of these particular MIME types                   have been supplied, we are a good candidate. -->             <intent-filter>                 <action android:name="android.intent.action.VIEW" />                 <category android:name="android.intent.category.BROWSABLE" />                 <category android:name="android.intent.category.DEFAULT" />                 <data android:scheme="http" />                 <data android:scheme="https" />                 <data android:scheme="inline" />                 <data android:mimeType="text/html"/>                 <data android:mimeType="text/plain"/>                 <data android:mimeType="application/xhtml+xml"/>                 <data android:mimeType="application/vnd.wap.xhtml+xml"/>             </intent-filter>                 <action android:name="android.intent.action.VIEW" />                 <category android:name="android.intent.category.DEFAULT" />                 <category android:name="android.intent.category.BROWSABLE" />                 <data android:scheme="file" />             </intent-filter>

外部调用就ok了,连file文件都能调用,若自己调用的话

Uri uri = Uri.parse("file://data/data/test.html");
//   Uri uri = Uri.parse("http://m.baidu.com");     
  Intent it = new Intent(Intent.ACTION_VIEW, uri);        
  context.startActivity(it);     


android浏览器开发小技巧集锦

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146453.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java 分苹果_数据结构Java版

    java 分苹果_数据结构Java版有600个苹果,10个盒子,要求把600个苹果分装到10个盒子里。如果有人来买苹果随便说出一个数,直接拿这些盒子组装一下就可以给他不用拆分盒子。请问这10个盒子应该分别装多少苹果?代码如下importjava.util.Scanner;publicclassTest{ publicstaticvoidmain(String[]args){  intbox[]=

    2022年10月12日
    0
  • LINUX之中iptables 开放端口

    LINUX之中iptables 开放端口比如要开放3306端口;方式:vi/etc/sysconfig/iptables编辑文件iptables-AINPUT-ptcp–dport3306-jACCEPT添加这行然后保存serviceiptablesrestart重启服务serviceiptablesstop关闭iptables假如遇到奇葩问题用…

    2022年10月21日
    0
  • Python实现softmax函数「建议收藏」

    Python实现softmax函数:PS:为了避免求exp(x)出现溢出的情况,一般需要减去最大值。#-*-coding:utf-8-*-importtensorflowastfimportnumpyasnpdefsoftmax(x,axis=1):#计算每行的最大值row_max=x.max(axis=axis)…

    2022年4月14日
    491
  • navicat15 mac激活码【最新永久激活】

    (navicat15 mac激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月30日
    209
  • c#启动外部程序_winform程序自动更新

    c#启动外部程序_winform程序自动更新//class里面放入这段代码[DllImport(“shell32.dll”)]publicstaticexternintShellExecute(IntPtrhwnd,StringBuilderlpszOp,StringBuilderlpszFile,StringBuilderlpszParams,StringBuilderlpszDir,intFsShowCmd);//需要打开的地方插入此段代码ShellExecute(IntPtr.Zero,newStr

    2022年8月30日
    1
  • MySQL常见备份方案

    MySQL常见备份方案

    2021年11月27日
    58

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号