【发布时间】:2017-08-26 18:36:45
【问题描述】:
目前,这就是我实现 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));
我想知道,是否可以将 Chrome 自定义标签作为 View 对象?
我问的原因是,以前,我有一个片段,它有 ViewAnimator 对象。 ViewAnimator 将在 2 WebViews 之间依次进行动画处理。
一个WevView 正在显示网页的移动版本。另一个WebView 正在显示网页的桌面版本。
这是用于在 2 个 WebViews 之间交替的代码
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);
}
这是 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>
有人告诉我Chrome Custom Tabs 的性能比WebView 好得多。
但是,我没有找到让单个片段包含 2 个不同的 Chrome 自定义选项卡的方法。因为,他们是Intent,而不是View。
但是,有什么办法可以让 Chrome 自定义标签页作为 View 对象?
【问题讨论】:
标签: android google-chrome webview chrome-custom-tabs