Last active
February 7, 2018 05:37
-
-
Save SalaSuresh/facce21bd7ccaeea195fdd049476df97 to your computer and use it in GitHub Desktop.
Android Chrome Custom Tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:fillAfter="true" > | |
<alpha | |
android:duration="1000" | |
android:fromAlpha="0.0" | |
android:interpolator="@android:anim/accelerate_interpolator" | |
android:toAlpha="1.0" /> | |
</set> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<set xmlns:android="http://schemas.android.com/apk/res/android" | |
android:fillAfter="true" > | |
<alpha | |
android:duration="1000" | |
android:fromAlpha="1.0" | |
android:interpolator="@android:anim/accelerate_interpolator" | |
android:toAlpha="0.0" /> | |
</set> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.suresh.chrometab; | |
import android.app.PendingIntent; | |
import android.content.Intent; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.graphics.Color; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.customtabs.CustomTabsIntent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import com.games4playstore.aroundyou.R; | |
/** | |
* Created by Suresh on 07-Feb-18. | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
Button mButtonOpenChrome; | |
Bitmap icon; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.layout_chrome_tab); | |
icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); | |
Intent intent = new Intent(MainActivity.this, MainActivity.class); | |
final PendingIntent pendingIntent = PendingIntent.getActivity(this, 1016, intent, 0); | |
mButtonOpenChrome = (Button) findViewById(R.id.button_open_chrome); | |
mButtonOpenChrome.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
String url = "https://developer.android.com/index.html"; | |
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); | |
//To add custom color to toolbar | |
builder.setToolbarColor(Color.GREEN); | |
//To add actionbutton to actionbar with respective intent | |
builder.setActionButton(icon, "description", pendingIntent, true); | |
//to add extra menu item with respective intent | |
builder.addMenuItem("menuItemTitle", pendingIntent); | |
//to add entry and exit animations to chrome tab | |
builder.setStartAnimations(MainActivity.this, R.anim.fade_in, R.anim.fade_out); | |
builder.setExitAnimations(MainActivity.this, R.anim.fade_in, R.anim.fade_out); | |
CustomTabsIntent customTabsIntent = builder.build(); | |
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url)); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment