Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
像Gmail应用程序一样在android WebView中处理外部链接_Android_Webview - Fatal编程技术网

像Gmail应用程序一样在android WebView中处理外部链接

像Gmail应用程序一样在android WebView中处理外部链接,android,webview,Android,Webview,我是一名网络开发者。我目前正在android Studio上开发android应用程序,使用WebView作为android应用程序访问我的网站。我的一个网页包含许多外部链接。我的目标是使android应用程序能够像Gmail应用程序那样处理外部链接(也像facebook和Line do)。 下面是gmail应用程序的示例 知道怎么做吗?很简单。在评论中,你必须使用Gergely的建议。下面是帮助您实现这一目标的小功能代码 首先将此依赖项添加到build.gradle(模块:app) 第二,

我是一名网络开发者。我目前正在android Studio上开发android应用程序,使用WebView作为android应用程序访问我的网站。我的一个网页包含许多外部链接。我的目标是使android应用程序能够像Gmail应用程序那样处理外部链接(也像facebook和Line do)。 下面是gmail应用程序的示例





知道怎么做吗?

很简单。在评论中,你必须使用Gergely的建议。下面是帮助您实现这一目标的小功能代码

首先将此依赖项添加到build.gradle(模块:app)

第二,将下面的函数添加到代码中,只需将字符串URL传递给它

private void redirectUsingCustomTab(String url)
{
    Uri uri = Uri.parse(url);

    CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();

    // set desired toolbar colors
    intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
    intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // add start and exit animations if you want(optional)
    /*intentBuilder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
            android.R.anim.slide_out_right);*/

    CustomTabsIntent customTabsIntent = intentBuilder.build();

    customTabsIntent.launchUrl(activity, uri);
}
休息吧,它会自己照顾自己的。因为Chrome自定义选项卡可以自定义,所以很多事情都可以做,就像你们可以将菜单添加到工具栏一样。有关详细信息,您可以访问谷歌自己的官方文档


希望它能帮助你开始:)

你需要的。嗨@GergelyKőrössy,谢谢你的帮助。。我会试试看。@Dika请检查演示代码否,您只需要传递服务器上托管的html页面的URL。如果用户尚未安装chrome浏览器,是否需要担心?我的意思是,它在没有安装chrome的情况下还能工作吗?
private void redirectUsingCustomTab(String url)
{
    Uri uri = Uri.parse(url);

    CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();

    // set desired toolbar colors
    intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
    intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // add start and exit animations if you want(optional)
    /*intentBuilder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
            android.R.anim.slide_out_right);*/

    CustomTabsIntent customTabsIntent = intentBuilder.build();

    customTabsIntent.launchUrl(activity, uri);
}