Chrome 自定義標籤的 CustomTabsIntent

Version >= 4.0.3

使用 CustomTabsIntent ,現在可以配置 Chrome 自定義標籤 ,以便在從你的應用開啟的瀏覽器中自定義關鍵 UI 元件。

對於某些情況,這是使用 WebView 的一個很好的替代方法。它允許載入帶有 Intent 的網頁,並增加了將應用程式的某種程度的外觀和感覺注入瀏覽器的能力。

以下是如何使用 CustomTabsIntent 開啟網址的示例

String url = "https://www.google.pl/";
CustomTabsIntent intent = new CustomTabsIntent.Builder()
                    .setStartAnimations(getContext(), R.anim.slide_in_right, R.anim.slide_out_left)
                    .setExitAnimations(getContext(), android.R.anim.slide_in_left, android.R.anim.slide_out_right)
                    .setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back_white_24dp))
                    .setToolbarColor(Color.parseColor("#43A047"))
                    .enableUrlBarHiding()
                    .build();
            intent.launchUrl(getActivity(), Uri.parse(url));

注意:

要使用自定義選項卡,你需要將此依賴項新增到 build.gradle

compile 'com.android.support:customtabs:24.1.1'