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

Flutter Android端调用Chrome浏览器时如何隐藏上下文菜单

你当前使用的flutter_inappwebview库中,Chrome自定义标签(Chrome Custom Tabs)的默认溢出菜单(右上角三点按钮)不会被你现有配置的参数控制:addDefaultShareMenuItem: false仅能隐藏菜单内的分享选项,其余参数也没有隐藏整个菜单的作用,因此无法达到你要的效果。

方案1:禁用所有默认菜单项

升级flutter_inappwebview到5.7.0及以上版本,在AndroidChromeCustomTabsOptions中添加defaultMenuItemsDisabled: true配置,即可禁用所有默认菜单项,点击三点按钮后不会展示任何内容。修改后的核心代码如下:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('MyApp'),
    ),
    body: Center(
      child: ElevatedButton(
          onPressed: () async {
            await widget.browser.open(
              url: Uri.parse(
                  "https://www.google.com/"),
              options: ChromeSafariBrowserClassOptions(
                android: AndroidChromeCustomTabsOptions(
                    enableUrlBarHiding: true,
                    instantAppsEnabled: false,
                    addDefaultShareMenuItem: false,
                    defaultMenuItemsDisabled: true, // 新增此行,禁用所有默认菜单项
                    toolbarBackgroundColor: Colors.cyan),
                ios: IOSSafariOptions(barCollapsingEnabled: true),
              ),
            );
          },
          child: Text("Open MyApp")),
    ),
  );
}

方案2:彻底隐藏三点按钮

如果需要完全移除右上角的三点按钮,可搭配沉浸式显示模式和隐藏标题配置实现,代码如下:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('MyApp'),
    ),
    body: Center(
      child: ElevatedButton(
          onPressed: () async {
            await widget.browser.open(
              url: Uri.parse(
                  "https://www.google.com/"),
              options: ChromeSafariBrowserClassOptions(
                android: AndroidChromeCustomTabsOptions(
                    enableUrlBarHiding: true,
                    instantAppsEnabled: false,
                    addDefaultShareMenuItem: false,
                    defaultMenuItemsDisabled: true,
                    displayMode: AndroidCustomTabsDisplayMode.IMMERSIVE, // 新增沉浸式模式配置
                    showTitle: false, // 新增隐藏工具栏标题配置
                    toolbarBackgroundColor: Colors.cyan),
                ios: IOSSafariOptions(barCollapsingEnabled: true),
              ),
            );
          },
          child: Text("Open MyApp")),
    ),
  );
}

注意事项

如果配置后不生效,请先确认你的flutter_inappwebview依赖版本是否符合要求,旧版本库未提供上述两个新增参数,升级到最新稳定版即可。

内容的提问来源于stack exchange,提问作者A Khan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 21:09:01