Introduction: https://developer.chrome.com/multidevice/android/customtabs#whentouse
Customize chrome tab: https://segunfamisa.com/posts/chrome-custom-tabs
Interface: https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.html https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.Builder.html
Github demos of chrome tab features: https://github.com/GoogleChrome/custom-tabs-client.git There are multiple apps inside.(list related features)
- Application/MainActivity
- bind CustomTabs Service (initialization and finalization) :
- Locate : MainActivity.java/bindCustomTabsService()
- Customize bottom tool bar (a mini music player) :
- Locate : BottomBarManager.java
- Feature : Can hide and show the bar by click or scroll
- Add a share button to top tool bar :
- Locate : MainActivity.java/prepareActionButton()
- Add menu item :
- Locate : MainActivity.java/prepareMenuItems()
- bind CustomTabs Service (initialization and finalization) :
- demos/CustomUIActivity
- Add Action Buttion
- Add default share
- Add toolbar item
- Show title
- Custom back button
- Auto-hide AppBar
- Set top and bottom toolbar color
// Set toolbar color
intentBuilder.setSecondaryToolbarColor(getResources().getColor(android.R.color.holo_red_light));
// add multiple tool bar
// Example of creating 5 buttons at bottom tool bar.
// i == 0 will create button at top.
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back);
for (int i = 1; i < 6; i++) {
PendingIntent pendingIntent = createPendingIntent(i);
intentBuilder.addToolbarItem(i, icon, actionLabel, pendingIntent);
}
private PendingIntent createPendingIntent(int actionSourceId) {
Intent actionIntent = new Intent(
this.getApplicationContext(), ActionBroadcastReceiver.class);
actionIntent.putExtra(ActionBroadcastReceiver.KEY_ACTION_SOURCE, actionSourceId);
return PendingIntent.getBroadcast(getApplicationContext(), actionSourceId, actionIntent, 0);
}
public class ActionBroadcastReceiver extends BroadcastReceiver {
public static final String KEY_ACTION_SOURCE = "org.chromium.customtabsdemos.ACTION_SOURCE";
@Override
public void onReceive(Context context, Intent intent) {
// get the link of current url
String url = intent.getDataString();
// get action id
int actionId = intent.getIntExtra(KEY\_ACTION\_SOURCE, -1);
handleAction(actionId);
}
public void handleAction(int actionId) {
switch (actionId) {
// Handle actions here
1. Save page
2. Share link
3. ...
}
}
}