[英]Chrome custom tab opens as a new tab in chrome not inside the app why?
如何在不在后台打开 Google Chrome 的情况下在我的应用程序中打开我的自定义选项卡...
这是我的代码
String a="http://www.gpamravati.ac.in/gpamravati";
CustomTabsIntent.Builder builder=new CustomTabsIntent.Builder();
CustomTabsIntent custom=builder.build();
custom.intent.setPackage("com.android.chrome");
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
custom.launchUrl(this, Uri.parse(a));
简而言之,您应该打开一个片段 OnNavigationItemSelectedListener 并使用打开的片段内的 webview 并打开 Url。
片段的xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
片段的java代码
public class UrlFragment extends Fragment {
private WebView mWebView;
//inflate the layout
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_url, container, false);
return v;
}
@Override
protected void onViewCreated(View view, Bundle savedInstanceState) {
mWebView = (WebView) view(R.id.main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.gpamravati.ac.in/");
mWebView.setWebViewClient(new WebViewClient());
}
}
以及在片段内的 webview 中打开 URL 所需的基本代码。 在这里阅读更多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.