Using a CustomTabsIntent
, it is now possible to configure Chrome custom tabs in order to customize key UI components in the browser that is opened from your app.
This is a good alternative to using a WebView for some cases. It allows loading of a web page with an Intent, with the added ability to inject some degree of the look and feel of your app into the browser.
Here is an example of how to open a url using CustomTabsIntent
String url = "https://www.google.pl/";
CustomTabsIntent intent = new CustomTabsIntent.Builder()
.setStartAnimations(getContext(), R.anim.slide_in_right, R.anim.slide_out_left)
.setExitAnimations(getContext(), android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back_white_24dp))
.setToolbarColor(Color.parseColor("#43A047"))
.enableUrlBarHiding()
.build();
intent.launchUrl(getActivity(), Uri.parse(url));
Note:
To use custom tabs, you need to add this dependency to your build.gradle
compile 'com.android.support:customtabs:24.1.1'