Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2017 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaisonfdo/f21e756b6fd5c3d2675643e42542da91 to your computer and use it in GitHub Desktop.
Save jaisonfdo/f21e756b6fd5c3d2675643e42542da91 to your computer and use it in GitHub Desktop.
This gist is used to implement Chrome Custom Tab in your Android app. For further details :
package com.droidmentor.chromecustomtab;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
String TAG = "MainActivity";
Button btnLaunch;
String url;
public static MainActivity instance = null;
protected void onCreate(Bundle savedInstanceState) {
instance = this;
btnLaunch = (Button) findViewById(;
btnLaunch.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Loading url
url = "";
// CustomTabsIntent.Builder used to configure CustomTabsIntent.
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setShowTitle(true);
// Change the background color of the Toolbar.
builder.setToolbarColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null));
// Configure custom enter and exit animations
builder.setStartAnimations(MainActivity.this, R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(MainActivity.this, R.anim.slide_in_left, R.anim.slide_out_right);
// Setting a custom back button
getResources(), R.drawable.ic_arrow_back));
// Hide status bar once the user scrolls down the content
// For adding menu item
builder.addMenuItem("Share", getItem());
// For adding Action button
R.drawable.ic_share), "Share", getItem(), true);
// CustomTabsIntent used to launch the URL
CustomTabsIntent customTabsIntent =;
//Open the Custom Tab
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));
private PendingIntent getItem() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Droidmentor is a site, which contains android tutorials");
Log.d(TAG, "setMenuItem: " + url);
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
return PendingIntent.getActivity(this, 0, shareIntent, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment