如何隐藏Chrome自定义选项卡菜单中的某些操作(例如书签和下载按钮)?

cpjpxq1n  于 2023-03-27  发布在  Go
关注(0)|答案(2)|浏览(204)

我在我的应用程序上使用Chrome自定义选项卡,我希望能够禁用一些按钮,当我启动它打开Google驱动器文件时,这些按钮会自动弹出,即用于为页面添加书签的按钮和用于下载的按钮。我已经在整个网络上搜索过,但没有任何运气。
下面是图像突出显示的按钮正是我寻求隐藏在我的自定义选项卡.有人知道如何实现这一点?!提前非常感谢你.

mi7gmzs6

mi7gmzs61#

有一个"hidden" API可以让你隐藏这些按钮:在启动Intent之前,添加一个键为org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_STAR_BUTTON、值为true的额外值,以禁用书签按钮,并添加一个键为org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON的额外值,以禁用下载按钮。
请注意,这并没有完全禁用 * 功能 *:仍然可以将自定义标签页重新设置为Chrome的父项,并在那里添加书签或下载页面。
另外请注意,这不是一个公共API,因此它可能会在未来的Chrome版本中消失。

qqrboqgw

qqrboqgw2#

最近几年的自定义选项卡,我们应该使用包androidx.browserhttps://developer.android.com/jetpack/androidx/releases/browser

dependencies {
    ...
    implementation "androidx.browser:browser:1.5.0"
    ...
}

要使用额外功能...

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();

// official way to disable share button
builder.setShareState(CustomTabsIntent.SHARE_STATE_OFF);

// official way to show website title in address bar 
builder.setShowTitle(true);

CustomTabsIntent customTabsIntent = builder.build();

// unofficial way to show website title in address bar
customTabsIntent.intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, 1);

// unofficial (only) way to disable download button
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON", true);

// unofficial (only) way to disable star button
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_STAR_BUTTON", true);

customTabsIntent.launchUrl(mainActivity, Uri.parse("https://example.com"));

你可以在https://chromium.googlesource.com/external/github.com/GoogleChrome/custom-tabs-client/+/master/customtabs/src/android/support/customtabs/CustomTabsIntent.java这里看到你可以修改的内容,但是几乎所有的常量你都可以在这里通过doc来修改:

更有趣的是,你还可以在Chromium源代码中进行更改:https://chromium.googlesource.com/chromium/src/+/refs/tags/103.0.5052.1/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java ...这里是EXTRA_DISABLE_DOWNLOAD_BUTTON & EXTRA_DISABLE_星星_BUTTON
查看没有下载和星星按钮的结果...

相关问题