android不推荐使用“settoolbarcolor(int)”和“setsecondarytoolbarcolor(int)”

9njqaruj  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(359)

我使用此代码打开带有chrome自定义选项卡的链接。但它正在显现 @Deprecated 为了 setToolbarColor() 以及 setSecondaryToolbarColor() . 我没有找到任何可以替换的。
注意:androidstudio建议“改用setdefaultcolorschemeparams”,但还没有找到这样的例子。

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);
gkl3eglg

gkl3eglg1#

使用 CustomTabColorSchemeParams 取而代之:参考

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);

相关问题