简体   繁体   English

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

[英]Chrome custom tabs not working correctly with CustomTabsIntent

I've been trying to explore the Google Chrome custom tabs tool but something is intriguing me. 我一直在尝试探索谷歌Chrome自定义标签工具,但有些东西让我很感兴趣。

Using the following version of the library on Android Studio 在Android Studio上使用以下版本的库

compile 'com.android.support:customtabs:23.2.0'

and then running a sample using the CustomTabsIntent isn't working as I expected. 然后使用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);

Using this, only the setToolbarColor() is working. 使用它,只有setToolbarColor()正在工作。 The setCloseButtonIcon() , addDefaultShareMenuItem() or even other instructions are not taking any effect. setCloseButtonIcon()addDefaultShareMenuItem()甚至其他指令都没有任何效果。

Does anybody has experienced something like this? 有没有人经历过这样的事情?

There are two different reason: 有两个不同的原因:

  • setCloseButtonIcon

    probably doesn't work because the bitmap you use has the wrong dimensions. 可能不起作用,因为您使用的位图具有错误的尺寸。 As documented by developer.android.com : 正如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. 图标的高度不应超过24dp(不需要填充。按钮本身的高度为48dp),宽度/高度比小于2。

    You can get the correct back arrow bitmap from the custom-tabs-client repo. 您可以从custom-tabs-client repo获取正确的后退箭头位图。

  • addDefaultShareMenuItem

    As you can see on chromium.org the default share button is a newly added feature and it currently works only with Chrome Beta and Chrome Dev . 正如您在chromium.org上看到的,默认共享按钮是一项新增功能,目前仅适用于Chrome BetaChrome Dev You need to wait that Chrome Stable will be updated with this feature, in the meantime this parameter will be ignored on the stable version. 您需要等待Chrome Stable使用此功能进行更新,同时此参数将在稳定版本中被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM