Android - 不推荐使用“setToolbarColor(int)”和“setSecondaryToolbarColor(int)”

7 java android google-chrome android-intent chrome-custom-tabs

我使用此代码打开带有 Chrome 自定义标签的链接。但它显示@DeprecatedsetToolbarColor()setSecondaryToolbarColor()。我没有找到任何可以替换的东西。

注意:Android Studio 建议“改用 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);
Run Code Online (Sandbox Code Playgroud)

MLF*_*MLF 12

使用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);
Run Code Online (Sandbox Code Playgroud)

  • @Arghadip,我在 Nexus 5 (API 30) 模拟器和设备上进行了测试。我认为我们应该在设备上测试这些案例。请参阅/sf/ask/4290715551/。您可以尝试“.setDefaultColorSchemeParams(params)”吗? (3认同)