Android-「setToolbarColor(int)」および「setSecondaryToolbarColor(int)」は非推奨になりました

Dec 13 2020

このコードを使用して、Chromeカスタムタブとのリンクを開きます。しかし、それはとの@Deprecatedために表示されsetToolbarColor()てい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);

回答

5 MLFR2kx Dec 13 2020 at 20:13

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