Android 自訂分頁總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Custom Tabs 是 Android 瀏覽器的功能,可讓應用程式開發人員直接在應用程式中新增自訂瀏覽器體驗。
自智慧型手機問世以來,載入網頁內容一直是行動應用程式的一部分,但舊版選項可能會對開發人員造成挑戰。對於無法自訂的使用者而言,啟動實際瀏覽器是繁重的內容切換作業,而 WebView 不支援網站平台的所有功能,也不會與瀏覽器共用狀態,並會增加維護成本。
使用者瀏覽網頁時,自訂分頁可讓他們留在應用程式中,進而提升參與度,並降低使用者放棄應用程式的風險。自訂分頁直接由使用者偏好的瀏覽器提供動力,並自動分享瀏覽器提供的狀態和功能。您不需要編寫自訂程式碼來管理要求、授權核准或 Cookie 存放區。
自訂分頁有哪些功能?
使用自訂分頁時,您的網頁內容會在使用者偏好的瀏覽器所使用的任何轉譯引擎中載入。任何 API 或網路平台功能都會在該處提供,並可供自訂分頁使用。瀏覽工作階段、已儲存的密碼、付款方式和地址都會如往常顯示。
我可以在自訂分頁中自訂哪些內容?
非常多!自訂分頁可讓您精細控管許多瀏覽器外觀和使用者體驗。您可以在應用程式中使用意圖啟動自訂分頁。在呼叫此意圖時,您可以為 CustomTabIntent 新增多個屬性,以獲得所需的確切體驗。以下列出可新增的部分自訂選項:
- 自訂進場和退場動畫,與應用程式的其他部分相符
- 修改工具列顏色,以配合應用程式的品牌
- 即使應用程式切換淺色和深色主題,也能維持一致的色彩
- 自訂動作和瀏覽器工具列和選單的項目
- 控制自訂分頁的啟動高度,例如在與網路商店互動時串流播放影片
此外,使用者可以最小化自訂分頁,與底層應用程式互動,並隨時還原,無須擔心會遺失任何進度,才能繼續瀏覽網頁。這樣一來,使用者就能在網站和原生應用程式之間流暢地進行多工處理,而無須關閉自訂分頁。這項功能預設為啟用。
這只是其中一部分。自訂分頁功能非常強大,且仍在積極開發中。每個瀏覽器都需要在這些功能推出時新增支援功能。雖然幾乎所有瀏覽器都提供某種程度的支援,但您還是需要瞭解使用者瀏覽器可能支援或不支援的功能。請參閱功能比較表,快速查看熱門 Android 瀏覽器是否支援各種功能。
您現在可以使用 GitHub 上的範例進行測試。
何時該使用自訂分頁?
沒有任何「正確」的網路內容載入方式。在某些情況下,WebView 會是適合的技術。舉例來說,如果您只在應用程式中代管自己的內容,或是需要直接從應用程式注入 JavaScript,或是應用程式會將使用者導向網域以外的網址,則自訂 Tabs 內建的共用狀態可能會是較佳的選擇。自訂分頁的其他優點包括:
- 安全性:自訂分頁會使用 Google 的安全瀏覽功能,保護使用者和裝置免受危險網站的攻擊。
- 效能最佳化:
- 在背景預先暖機瀏覽器,同時避免從應用程式竊取資源。
- 提前推測載入網址,加快網頁載入時間。
- 生命週期管理:系統不會在使用分頁時將啟動自訂分頁的應用程式逐出。自訂分頁的重要性會提升至「前景」等級。
- 共用 Cookie 罐和權限模型,讓使用者不必登入已連結的網站,或重新授予已授予的權限。
- 瀏覽器功能 (例如自動填入功能,可讓您更輕鬆地填寫表單) 隨附於系統中。
- 使用者可以透過內建的返回按鈕返回應用程式。
自訂分頁與受信任的網路活動
Trusted Web Activities 可擴充 Custom Tabs 通訊協定,並提供大部分的優點。但它並未提供自訂 UI,而是讓開發人員能夠在不使用任何 UI 的情況下開啟瀏覽器分頁。開發人員如要以全螢幕模式在自家 Android 應用程式中開啟自家的漸進式網頁應用程式,建議採用這種做法。
自訂分頁適用於哪些國家/地區?
自訂分頁是 Android 平台上的瀏覽器支援的功能。這項功能最初是在 Chrome 45 版推出。大多數 Android 瀏覽器都支援這項通訊協定。
我們希望收到有關這個專案的意見回饋、問題和建議,因此建議您前往 crbug.com 提出問題,並在 Twitter 上向 @ChromiumDev 提問。
瞭解詳情
如有任何疑問,請前往 StackOverflow 查看 chrome-custom-tabs 標記。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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."]]