Chrome Custom Tabs

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值