I am trying to change the default close button on the actionbar of the custom chrome tabs. I have tried to set using setCloseButtonIcon()
However, the default close button still shows. I want to change the close to an arrow.
My code below:
public void openHomePage() {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(ContextCompat.getColor(getActivity(), R.color.primary));
final Bitmap backButton = BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back_black_48dp);
builder.setCloseButtonIcon(backButton);
builder.setShowTitle(true);
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(getActivity(), Uri.parse(mTvHomepage.getText().toString()));
}
Let, you open chrome custom tab from "MainActivity" and there is a option menu item "Close" in chrome custom tab, and on "Close" menu item click you want to close chrome custom tab and to go back the "MainActivity", then you can do it by starting "MainActivity".
Custom Tabs is a browser feature, introduced by Chrome, that is now supported by most major browsers on Android. It gives apps more control over their web experience, and makes transitions between native and web content more seamless without having to resort to a WebView.
I have an observation. Last month, when searching through SO for various chrome custom tab issues, I found this answer suggesting to use 24dp size icon and also found this question saying that it is working fine with PNG.
I have checked your code with using back arrow icon from here.
When I used "ic_arrow_back_black_48dp", it didn't change the default close button to an arrow (see left image).
final Bitmap backButton = BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back_black_48dp);
But when I used "ic_arrow_back_black_24dp", it perfectly changed the default close button to an arrow (see right image).
final Bitmap backButton = BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back_black_24dp);
As it has worked perfectly for me, you should also try with "24dp" size back arrow icon from here instead of "48dp" size back arrow icon.
Screenshot : [ Device: ASUS_Z00UD; OS: 6.0.1 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With