android - Chrome 自定义标签无法与 CustomTabsIntent 一起正常工作

标签 android google-chrome chrome-custom-tabs

我一直在尝试探索 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 BetaChrome Dev .你需要等待 Chrome Stable将使用此功能进行更新,同时此参数将在稳定版本中被忽略。

关于android - Chrome 自定义标签无法与 CustomTabsIntent 一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746097/

相关文章:

android - Chrome 自定义标签的自定义关闭按钮

ASP.Net FileUpload 控件导致 google chrome 崩溃并显示损坏的数据

javascript - 如何自动点击元素

android - 为什么 Android Chrome 从 61.0.3163.98 更新到 72.0.3626.76 会破坏 Chrome 自定义选项卡中的 OAuth 登录?

android - 加载 fragment 时出现 NullPointerException

安卓工作室 : uploading user data after email validation using firebase

android - 如何将数据从应用程序发送到 AppWidgetProvider?

android - 如何将数据传递给前一个 Activity 之前的 Activity

javascript - Chrome 扩展程序 : How to Manage separate instances of background pages?

android - 没有为深层链接捕获 Chrome 自定义选项卡中的重定向