Android 自定义标签页概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
自定义标签页是 Android 浏览器的一项功能,可让应用开发者直接在其应用中添加自定义浏览器体验。
从智能手机问世之初起,加载 Web 内容就已成为移动应用的一部分,但旧版选项可能会给开发者带来挑战。启动实际浏览器对用户来说是一项无法自定义的重量级上下文切换,而 WebView 不支持 Web 平台的所有功能,不会与浏览器共享状态,并且会增加维护开销。
借助自定义标签页,用户可以在浏览时保持在应用内,从而提高互动度并降低用户放弃应用的风险。自定义标签页由用户的首选浏览器直接提供支持,并会自动共享该浏览器提供的状态和功能。您无需编写自定义代码即可管理请求、权限授予或 Cookie 存储区。
自定义标签页有哪些功能?
使用自定义标签页后,您的 Web 内容会在用户首选浏览器所使用的任何渲染引擎中加载。您可以在该页面中使用任何 API 或 Web 平台功能,也可以在“自定义”标签页中使用这些功能。他们的浏览会话、已保存的密码、付款方式和地址都会显示出来,就像他们已经习惯的那样。
我可以在“自定义”标签页中自定义哪些内容?
非常有用!借助自定义标签页,您可以对许多浏览器界面和用户体验进行精细控制。在应用中,您可以使用 intent 启动自定义标签页。调用此 intent 时,您可以向 CustomTabIntent 添加多个属性,以获得所需的确切体验。下面列出了您可以添加的一些自定义内容:
- 自定义进入和退出动画,以与应用的其余部分保持一致
- 修改工具栏颜色以匹配应用的品牌
- 颜色一致性,即使应用在浅色主题和深色主题之间切换,也能保持一致
- 向浏览器的工具栏和菜单添加自定义操作和条目
- 控制自定义标签页的启动高度,以便在与您的网店互动时流式传输视频等
此外,用户可以最小化自定义标签页以与底层应用互动,并随时恢复该标签页,而不会丢失任何进度,从而继续其历程。这样,用户便可以关闭自定义标签页,从而在网站和原生应用之间无缝执行多任务。自定义标签页默认启用此功能。
这远远不是全部。自定义标签页功能非常强大,并且正在积极开发中。每款浏览器都需要在这些功能推出后添加对这些功能的支持。虽然几乎所有浏览器都提供某种程度的支持,但了解用户的浏览器可能支持或不支持哪些功能非常重要。请参阅功能对比表,快速查看各款热门 Android 浏览器是否支持不同功能。
您现在可以使用 GitHub 上的示例进行测试。
何时应使用自定义标签页?
加载 Web 内容没有单一的“正确”方式。在某些情况下,WebView 是合适的技术。例如,如果您仅在应用内托管自己的内容,或者需要直接从应用注入 JavaScript。如果您的应用会将用户定向到网域外的网址,则自定义标签页中的内置共享状态可能更适合。自定义标签页的其他优势包括:
- 安全性:自定义标签页使用 Google 的安全浏览功能来保护用户和设备免受危险网站的侵害。
- 性能优化:
- 在后台预热浏览器,同时避免从应用窃取资源。
- 通过提前推测性加载网址来加快网页加载速度。
- 生命周期管理:在自定义标签页使用期间,系统不会驱逐启动自定义标签页的应用。自定义标签页的重要性会提升到前台级别。
- 共享 Cookie Jar 和权限模型,让用户无需登录已关联的网站,也不必重新授予已授予的权限。
- 开箱即用,即可使用自动填充等浏览器功能,更轻松地填写表单。
- 用户可以使用集成的返回按钮返回应用。
自定义标签页与 Trusted Web Activity
Trusted Web Activity 扩展了自定义标签页协议,并具有其大部分优势。不过,它并非提供自定义界面,而是允许开发者在不使用任何界面的情况下打开浏览器标签页。如果开发者希望在自己的 Android 应用中以全屏模式打开自己的渐进式 Web 应用,则建议使用此 API。
在哪些平台上可以使用自定义标签页?
自定义标签页是 Android 平台上浏览器支持的一项功能。它最初由 Chrome 45 版引入。大多数 Android 浏览器都支持该协议。
我们期待收到有关此项目的反馈、问题和建议,因此建议您在 crbug.com 上提交问题,并在 Twitter 上向 @ChromiumDev 提问。
了解详情
如有疑问,请查看 StackOverflow 上的 chrome-custom-tabs 标签。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Overview of Android Custom Tabs\n\nCustom Tabs are a feature in Android browsers that gives app developers\na way to add a customized browser experience directly within their app.\n\nLoading web content has been a part of mobile apps since the early days of\nsmartphones, but older options can present challenges for developers. Launching\nthe actual browser is a heavy context switch for users that isn't customizable,\nwhile WebViews [don't support](https://research.google/pubs/pub46739/) all features of the web platform, don't share\nstate with the browser and add maintenance overhead.\n\nCustom Tabs lets users remain within the app while browsing, increasing\nengagement and reducing the risk of users abandoning the app. Custom Tabs are\npowered directly by the user's preferred browser and automatically share the\nstate and features offered by it. You don't need to write custom code to manage\nrequests, permission grants, or cookie stores.\n\nWhat can Custom Tabs do?\n------------------------\n\nBy using a Custom Tab, your web content loads in whatever rendering engine\npowers your user's preferred browser. Any API or web platform feature is\navailable there, and is available in your Custom Tab. Their browsing session,\nsaved passwords, payment methods, and addresses all show up just like they\nare accustomed to already.\n\nWhat can I customize in a Custom Tab?\n-------------------------------------\n\nQuite a bit! Custom Tabs give you fine grained control over a lot of the browser\nchrome and user experience. Within your app, you launch a Custom Tab using an\n[Intent](https://developer.android.com/guide/components/intents-filters). When this Intent is called, you can add a number of attributes to\nthe [CustomTabIntent](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent) to get the exact experience you want. Some\ncustomizations that you can add are listed here:\n\n- Custom entrance and exit animations to match the rest of your app\n- Modifing the toolbar color to match your app's branding\n- Color consistency that can stay with your app, even if they switch between light and dark themes\n- Custom actions and entries to the browser's toolbar, and menus\n- Control the launch height of the Custom Tab, enabling things like streaming your videos while interacting with your web store\n\nIn addition, users can minimize a Custom Tab to interact with the underlying\napp, and restore it at any time without losing any progress to resume their\njourney. This gives users an alternative to closing the Custom Tab so they can\nseamlessly multitask between the web and the native app. The feature is\nenabled by default for Custom Tabs.\n\nThat is far from everything. Custom Tabs are very powerful, and under active\ndevelopment. Each browser needs to add support for these features as they become\navailable. While nearly all have some level of support, it is important to know\nwhat may or may not be available in your user's browsers. Refer to the\n[feature comparison table](/docs/android/custom-tabs/browser-support) to quickly\ncheck the availability of the different features across popular Android\nbrowsers.\n\nYou can test this now with our [sample](https://github.com/GoogleChrome/android-browser-helper/tree/master/demos/custom-tabs-example-app) on GitHub.\n\nWhen should I use Custom Tabs?\n------------------------------\n\nThere is no single \"correct\" way to load web content. In certain situations,\nWebView is going to be the right technology to use. For example, if you are\nexclusively hosting your own content inside your app, or if you need to inject\njavascript directly from your app. If your app directs people to URLs outside\ndomains, the built-in shared state in Custom Tabs means they are likely a\nbetter choice. Other strengths of Custom Tabs include:\n\n1. Security: Custom Tabs use Google's Safe Browsing to protect the user and the device from dangerous sites.\n2. Performance optimization:\n 1. Pre-warming of the Browser in the background, while avoiding stealing resources from the application.\n 2. Speed up the page load time by speculatively loading URLs in advance.\n3. Lifecycle management: Apps launching a Custom Tab won't be evicted by the system during the Tab's use. The importance of the Custom Tab is raised to the *foreground* level.\n4. Shared cookie jar and permissions model so users don't have to sign in to sites they are already connected to, or re-grant permissions they have already granted.\n5. Browser features like autofill for better form completion are available out-of-the-box.\n6. Users can return to app with an integrated back button.\n\nCustom Tabs versus Trusted Web Activity\n---------------------------------------\n\n[Trusted Web Activities](/develop/ui/views/layout/webapps/trusted-web-activities) extend the Custom Tabs protocol and shares most of\nits benefits. But, instead of providing a customized UI, it allows developers to\nopen a browser tab without any UI at all. It is recommended for developers who\nwant to open their own [Progressive Web App](https://web.dev/progressive-web-apps/), in full screen, inside their\nown Android app.\n\nWhere are Custom Tabs available?\n--------------------------------\n\nCustom Tabs is a feature supported by browsers on the Android platform. It was\noriginally introduced by [Chrome](https://play.google.com/store/apps/details?id=com.android.chrome), on version 45. The protocol is supported\nby most Android browsers.\n\nWe're looking for feedback, questions and suggestions on this project, so we\nencourage you to file issues on [crbug.com](https://crbug.com) and ask questions on Twitter\n[@ChromiumDev](https://twitter.com/ChromiumDev).\n\nLearn more\n----------\n\nFor questions, check the [chrome-custom-tabs](https://stackoverflow.com/questions/tagged/chrome-custom-tabs) tag on StackOverflow."]]