Android-" setToolbarColor(int)"和"setSecondaryToolbarColor(int)";不推荐使用 [英] Android - "setToolbarColor(int)" and "setSecondaryToolbarColor(int)" is deprecated

查看:93
本文介绍了Android-" setToolbarColor(int)"和"setSecondaryToolbarColor(int)";不推荐使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码打开带有Chrome自定义标签的链接.但是它显示了 setToolbarColor() setSecondaryToolbarColor() @Deprecated .我还没有找到可替换的东西.

I use this code to open links with Chrome Custom Tabs. But it's showing @Deprecated for setToolbarColor() and setSecondaryToolbarColor(). I haven't found anything for replacement.

注意:Android Studio建议改为使用setDefaultColorSchemeParams".但还没有找到任何例子.

Note: Android studio suggests "Use setDefaultColorSchemeParams instead." but haven't found any examples of that.

        Uri uri = Uri.parse(url);
        CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
        intentBuilder.setToolbarColor(ContextCompat.getColor(activity,R.color.background));
        intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(activity,R.color.background));
        intentBuilder.setStartAnimations(activity,R.anim.slide_in_right,R.anim.slide_out_left);
        intentBuilder.setExitAnimations(activity,android.R.anim.slide_in_left,android.R.anim.slide_out_right);
        CustomTabsIntent customTabsIntent = intentBuilder.build();
        customTabsIntent.launchUrl(activity,uri);

推荐答案

改为使用 CustomTabColorSchemeParams :

Use CustomTabColorSchemeParams instead: Reference

Uri uri = Uri.parse(url);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
CustomTabColorSchemeParams params = new CustomTabColorSchemeParams.Builder()
    .setNavigationBarColor(ContextCompat.getColor(activity,R.color.background))
    .setToolbarColor(ContextCompat.getColor(activity,R.color.background))
    .setSecondaryToolbarColor(ContextCompat.getColor(activity,R.color.background))
    .build();
intentBuilder.setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_DARK, params);
intentBuilder.setStartAnimations(activity, R.anim.slide_in_right,R.anim.slide_out_left);
intentBuilder.setExitAnimations(activity,android.R.anim.slide_in_left,android.R.anim.slide_out_right);
CustomTabsIntent customTabsIntent = intentBuilder.build();
customTabsIntent.launchUrl(activity,uri);

这篇关于Android-" setToolbarColor(int)"和"setSecondaryToolbarColor(int)";不推荐使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆