如何在我的应用中打开自定义标签,而无需在后台打开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));
答案 0 :(得分:3)
答案 1 :(得分:0)
简而言之, 你应该打开一个片段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所需的基本代码。阅读更多here