简体   繁体   English

是否可以将 Chrome 自定义标签作为视图对象

[英]Is it possible to have Chrome custom tabs as View object

Currently, this is how I implement Chrome custom tabs目前,这就是我实现 Chrome 自定义标签的方式

String url = "http://www.google.com/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(WelcomeFragment.this.getActivity(), Uri.parse(url));

I was wondering, is it possible to have Chrome custom tabs as View object?我想知道,是否可以将 Chrome 自定义标签作为 View 对象?

The reason I'm asking so that that, previously, I have a fragment, which is having ViewAnimator object.我之所以这么问,是因为之前我有一个片段,它具有ViewAnimator对象。 ViewAnimator will in-turn animate between 2 WebView s. ViewAnimator将依次在 2 个WebView之间设置动画。

One WevView is displaying mobile version of the web page.一个WevView正在显示网页的移动版本。 Another WebView is displaying desktop version of the web page.另一个WebView正在显示网页的桌面版本。

Here's the code which used to alternate between the 2 WebView s这是用于在 2 WebView之间交替的代码

public void updateWebView() {
    int index = getCurrentWebViewHolderIndex();
    final WebViewHolder webViewHolder = webViewHolders[index];
    if (webViewHolder == null) {
        return;
    }

    final WebView webView = webViewHolder.webView;

    boolean loadUrl = false;
    boolean reload = false;

    synchronized (monitor) {
        if (false == webViewHolder.loadUrl) {
            webViewHolder.loadUrl = true;
            loadUrl = true;
        } else if (webViewHolder.error) {
            webViewHolder.error = false;
            reload = true;
        }
    }

    if (loadUrl) {
        webView.loadUrl(getUrl(index));
    } else if (reload) {
        webView.reload();
    }

    final WebViewFragmentActivity activity = (WebViewFragmentActivity)WebViewFragment.this.getActivity();
    if (activity != null) {
        final int progress = webViewHolder.progress;

        if (progress >= 100) {
            activity.setProgressBarVisibilityEx(false);
        } else {
            activity.setProgressBarVisibilityEx(true);
            activity.setProgressEx(progress);
        }
    }

    if (index == 0) {
        // Slide from left.
        Animation slideInLeftFast = AnimationUtils.loadAnimation(this.getActivity(), R.anim.slide_in_left_fast);
        Animation slideOutRightSlow = AnimationUtils.loadAnimation(this.getActivity(), R.anim.slide_out_right_slow);
        this.webViewViewAnimator.setInAnimation(slideInLeftFast);
        this.webViewViewAnimator.setOutAnimation(slideOutRightSlow);
    } else {
        // Slide from right.
        Animation slideInRightFast = AnimationUtils.loadAnimation(this.getActivity(), R.anim.slide_in_right_fast);
        Animation slideOutLeftSlow = AnimationUtils.loadAnimation(this.getActivity(), R.anim.slide_out_left_slow);
        this.webViewViewAnimator.setInAnimation(slideInRightFast);
        this.webViewViewAnimator.setOutAnimation(slideOutLeftSlow);
    }

    if (webViewViewAnimator.getChildCount() >= 2) {
        webViewViewAnimator.removeViewAt(0);
    }
    webViewViewAnimator.addView(webView);
    webViewViewAnimator.setDisplayedChild(webViewViewAnimator.getChildCount() - 1);
}

Here's the XML code这是 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/web_view_linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal" >

    <ViewAnimator
        android:id="@+id/web_view_view_animator"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
    />

</LinearLayout>

I was told that Chrome Custom Tabs is having a much better performance than WebView .有人告诉我Chrome Custom Tabs 的性能比WebView好得多。

However, I don't find a way, to let single fragment holding 2 different Chrome Custom Tabs.但是,我没有找到让单个片段包含 2 个不同的 Chrome 自定义标签的方法。 As, they are Intent , not View .因为,它们是Intent ,而不是View

But, is there any way, to have Chrome custom tabs as View object?但是,有什么办法可以让 Chrome 自定义标签作为 View 对象?

Chrome Custom Tabs, will launch its own UI on a full screen. Chrome 自定义标签,将在全屏上启动自己的用户界面。 You cannot have it like a View in XML or Java/Kotlin.你不能像 XML 或 Java/Kotlin 中的视图那样拥有它。

As per the docs here -https://developer.chrome.com/docs/android/custom-tabs/overview/ , it lets you customize 3 things in the UI only -根据此处的文档 -https://developer.chrome.com/docs/android/custom-tabs/overview/ ,它仅允许您在 UI 中自定义 3 项内容 -

  1. Toolbar color工具栏颜色
  2. Enter and exit animations进入和退出动画
  3. Add custom actions to the browser toolbar, overflow menu and bottom toolbar向浏览器工具栏、溢出菜单和底部工具栏添加自定义操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM