Chrome自定义标签与CustomTabsIntent无法正常配合使用

yug*_*oid 3 android google-chrome chrome-custom-tabs

我一直在尝试探索谷歌Chrome自定义标签工具,但有些东西让我很感兴趣.

在Android Studio上使用以下版本的库

compile 'com.android.support:customtabs:23.2.0'
Run Code Online (Sandbox Code Playgroud)

然后使用它运行一个样本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);
Run Code Online (Sandbox Code Playgroud)

使用这个,只有setToolbarColor()工作正常.这些setCloseButtonIcon(), addDefaultShareMenuItem()甚至其他指示都没有起到任何作用.

有没有人经历过这样的事情?

Mat*_*ini 10

有两个不同的原因:

  • setCloseButtonIcon

    可能不起作用,因为您使用的位图具有错误的尺寸.正如developer.android.com所记录的那样 :

    指定要用作操作按钮的图像源的位图的键.图标的高度不应超过24dp(不需要填充.按钮本身的高度为48dp),宽度/高度比小于2.

    您可以从custom-tabs-client repo 获取正确的后退箭头位图.

  • addDefaultShareMenuItem

    正如您在chromium.org上看到的,默认共享按钮是一项新增功能,目前仅适用于Chrome BetaChrome Dev.您需要等待Chrome Stable使用此功能进行更新,同时此参数将在稳定版本中被忽略.