How can I open my custom tab inside my app without opening Google Chrome in background...
this is my code
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));
in short, you should open a fragment OnNavigationItemSelectedListener and use the webview inside the opened fragment and open the Url.
xml for fragment
<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 code for fragment
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());
}
}
and that the basic code needed to open a URL in webview inside the fragment. Read morehere
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.