我一直在尝试探索 Google Chrome 自定义标签页工具,但有些东西让我很感兴趣。
在 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()
甚至其他指令均未生效。
有人遇到过这样的事情吗?
最佳答案
有两种不同的原因:
设置关闭按钮图标
可能不起作用,因为您使用的位图 尺寸错误。正如所记录的 developer.android.com :
Key that specifies the Bitmap to be used as the image source for the action button. The icon should't be more than 24dp in height (No padding needed. The button itself will be 48dp in height) and have a width/height ratio of less than 2.
您可以从 custom-tabs-client 中获得正确的后退箭头 位图 repo 。
添加默认共享菜单项
正如您在 chromium.org 上看到的那样默认的共享按钮是一个新添加的功能,它 目前仅适用于 Chrome Beta和 Chrome Dev .你需要等待 Chrome Stable将使用此功能进行更新,同时此参数将在稳定版本中被忽略。
关于android - Chrome 自定义标签无法与 CustomTabsIntent 一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746097/