You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中如何禁用CustomChromeTab滚动时隐藏顶部栏及次级工具栏?

如何禁用Custom Chrome Tab的网址栏与次级工具栏自动隐藏

当然可以!你找对方向了——enableUrlBarHiding就是专门用来控制这个行为的开关。

默认情况下,这个方法的参数是true,也就是页面滚动时会自动隐藏网址栏和底部的次级工具栏。只要把它设置为false,就能让这两个栏始终保持可见,完全符合你的需求。

具体实现代码示例

以Kotlin为例,在构建CustomTabsIntent的时候添加这个配置:

import android.content.Context
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat

// 构建CustomTabsIntent Builder
val customTabBuilder = CustomTabsIntent.Builder()

// 配置你的次级工具栏(比如设置颜色、添加按钮等)
customTabBuilder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.your_toolbar_color))
// 这里是关键:禁用自动隐藏行为
customTabBuilder.enableUrlBarHiding(false)

// 构建并启动Custom Chrome Tab
val customTabsIntent = customTabBuilder.build()
customTabsIntent.launchUrl(context, Uri.parse("https://your-target-url.com"))

补充说明

  • 这个方法的核心作用就是控制滚动时的栏位隐藏逻辑,设置为false后,无论页面如何滚动,顶部网址栏和底部次级工具栏都会固定显示。
  • 确保你使用的是AndroidX版本的androidx.browser:browser库,这个方法在主流版本中都是稳定支持的。

内容的提问来源于stack exchange,提问作者Wang Ye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:03:32