How to change a title color in Chrome Custom Tabs

依然范特西╮ 提交于 2019-12-03 11:24:19

问题


Is there any way to change a title color in Chrome Custom Tabs?

I applied Chrome custom tabs to show a web page. To do, I utilized CustomTabsIntent.Builder class. However, there is no interface to change a title color.

String url = "www.google.com";
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(getResources().getColor(R.color.primary));
intentBuilder.setShowTitle(true);
intentBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back));
intentBuilder.setStartAnimations(getActivity(), R.anim.slide_in_right, R.anim.slide_out_left);
intentBuilder.setExitAnimations(getActivity(), android.R.anim.slide_in_left, android.R.anim.slide_out_right);
CustomTabActivityHelper.openCustomTab(getActivity(), intentBuilder.build(), Uri.parse(url), new WebviewFallback());

Based on the above code, Chrome Custom Tabs displays a black-colored title text. I want to change the title to a white color.


回答1:


You can't change color of tittle programmatically in Chrome Custom Tab. The only way you can follow is Material Design Specifications.

If you have primary and primaryDark color of your app with dark shade, than Custom Tabs will use dark tittle, dark close button and dark overflow menu button.

If you have primary and primaryDark color with light shade, than Chrome Custom Tabs will use light tittle etc.

So, you must pay attention on number of you primary and primaryDark color.




回答2:


It would be nice if there was a possibility to change the color of the text and statusbar. For example our app has different color settings so now there's no coherence between the app and Chrome Custom Tabs. That looks kinda bad.

Maybe there's a chance to get Chrome Custom Tabs colors for text and statusbar so that we could adjust it to our app (we have templates that user can choose).




回答3:


As mentioned in one of the responses, the title text color is chosen automatically for the best contrast with the title color, there is no other way to set it.




回答4:


Set the toolbar color.

intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));


来源:https://stackoverflow.com/questions/32533069/how-to-change-a-title-color-in-chrome-custom-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!