Chrome浏览器自定义选项卡与CustomTabsIntent无法正常工作
问题描述:
我一直在尝试探索谷歌浏览器自定义选项卡工具,但有些东西让我感兴趣。Chrome浏览器自定义选项卡与CustomTabsIntent无法正常工作
在Android Studio中使用该库的以下版本
compile 'com.android.support:customtabs:23.2.0'
,然后运行使用CustomTabsIntent
不工作如我所料的样品。
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(customTabActivityHelper.getSession())
.setCloseButtonIcon(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_action_back))
.setToolbarColor(Color.RED)
.addDefaultShareMenuItem()
.build();
CustomTabActivityHelper.openCustomTab(getActivity(), customTabsIntent, Uri.parse(url), null);
使用这个,只有setToolbarColor()
正在工作。 setCloseButtonIcon()
,addDefaultShareMenuItem()
甚至其他说明不起作用。
有没有人经历过这样的事情?
答
有两个不同的理由:
-
setCloseButtonIcon
可能不工作,因为你使用 位图有错误的尺寸。如记录由 developer.android.com:
密钥,它指定位图被用作 动作按钮图像源。图标should't超过24dp的高度(没有 填充需要,按钮本身将是高度48dp)和具有小于2
一个 宽度/高度比可以得到正确的返回箭头位图从custom-tabs-client回购。
-
addDefaultShareMenuItem
正如你可以看到chromium.org默认的共享按钮是新增加的功能,它 目前只适用Chrome Beta和Chrome Dev工作。您需要等待Chrome Stable将使用此功能进行更新,同时此稳定版本中的参数将被忽略。
太棒了!非常感谢。 – yugidroid