Chrome Custom Tabs

来源:互联网 发布:thinking in java 5 编辑:程序博客网 时间:2024/05/21 11:19

Chrome Custom Tabs 标签优点

Chrome自定义标签页(Custom Tabs)将允许应用预加载,从而将网页的加载时间直接减半。
它的速度比WebView更快,预加载的效果甚至好于Chrome本身。
持良好的用户体验,并且让用户感觉这个自定义 Tab 就是您应用的一部分。
使用方法比WebView 简单,只需要一行代码,和直接调用系统浏览器显示网页没啥区别
有大量自定义属性,改善用户体验

使用方法

需要导入Custom Tabs 的支持包:
compile ‘com.android.support:customtabs:23.1.0’

最简单的使用方式是只需要使用 CustomTabsIntent.Builder 对象来设置一些常用自定义选项,然后调用 CustomTabsIntent.launchUrl(Activity context, Uri url) 函数即可。当然在具体使用过程中,您还需要判断用户手机是否支持 Custom Tabs。

配置属性:

 CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();    // 修改 ActionBar 的颜色    intentBuilder.setToolbarColor(Color.RED);    // 添加一个分享按钮    String shareLabel = "分享";    Bitmap icon = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_menu_share);    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, BlankActivity.class), 0);    intentBuilder.setActionButton(icon, shareLabel, pendingIntent);    //添加Menu 按钮    intentBuilder.addMenuItem("打开", pendingIntent);    //是否显示网页标题    intentBuilder.setShowTitle(true);    //隐藏网页Bar    intentBuilder.enableUrlBarHiding();    //自定义关闭 Custom tabs 的图标    intentBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));    //自定义 Activity 转场 动画    intentBuilder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);    intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);    CustomTabsIntent customTabsIntent = intentBuilder.build();//    customTabsIntent.launchUrl(this, Uri.parse("http://www.51offer.com/"));
0 0
原创粉丝点击