为了让自己不浑浑噩噩的看代码,抄代码,看解释,对每天的学习进度做一个总结,虽然不知道能坚持多久。
1. Custom Tabs
为了提高用户体验,在用app打开浏览器的时候,能够定制Chrome的外观和操作。
- 将 Custom Tabs Support Library 添加到工程中来
dependencies {
...
compile 'com.android.support:customtabs:23.3.0'
} 打开一个Chrome Custom Tab
使用CustomTabsIntent.Builder配置CustomTabsIntent
准备完成后,调用CustomTabsIntent.Builder.build()方法创建一个CustomTabsIntent 并通过CustomTabsIntent.launchUrl()方法加载希望加载的url
String url = ¨https://github.com/marktony¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));配置地址栏的颜色
// 改变toolbar的背景色。colorInt就是想要指定的int值
builder.setToolbarColor(colorInt);配置定制化的action button
// 向toolbar添加一个Action Button
// ‘icon’是一张位图(Bitmap),作为action button的图片资源使用
// 'description'是一个字符串,作为按钮的无障碍描述所使用
// 'pendingIntent' 是一个PendingIntent,当action button或者菜单项被点击时调用。
// 在url作为data被添加之后,Chrome 会调用PendingIntent#send()方法。
// 客户端应用会通过调用Intent#getDataString()获取到URL
// 'tint'是一个布尔值,定义了Action Button是否应该被着色
builder.setActionButton(icon, description, pendingIntent, tint);
还没看完,明天继续。