package com.google.android.material.tabs;

import android.graphics.drawable.Drawable;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.ViewCompat;

public final class TabLayoutUtils {
    @Nullable
    public static Drawable getBackground(@NonNull final TabLayout.Tab tab) {
        return tab.view.getBackground();
    }

    @NonNull
    public static TabLayout.Tab setBackground(@NonNull final TabLayout.Tab tab, @Nullable final Drawable background) {
        ViewCompat.setBackground(tab.view, background);
        return tab;
    }

    @NonNull
    public static TabLayout.Tab setBackgroundTint(@NonNull final TabLayout.Tab tab, @ColorInt final int tint) {
        Drawable bkg = tab.view.getBackground();
        if (bkg != null) {
            bkg = DrawableCompat.wrap(bkg).mutate();
            DrawableCompat.setTint(bkg, tint);
        }
        setBackground(tab, bkg);
        return tab;
    }

    @NonNull
    public static TabLayout.Tab setVisibility(@NonNull final TabLayout.Tab tab, final int visibility) {
        tab.view.setVisibility(visibility);
        return tab;
    }
}

@@ -80,16 +80,49 @@
 wable;%0A%0A
+import java.lang.reflect.Field;%0A%0A
 import a
@@ -289,37 +289,25 @@
 ort 
-androidx.core.view.ViewCompat
+timber.log.Timber
 ;%0A%0Ap
@@ -341,16 +341,128 @@
 Utils %7B%0A
+    private static final String TAG = %22TabLayoutUtils%22;%0A    private static Field sBaseBackgroundDrawableField;%0A%0A
     @Nul
@@ -736,55 +736,450 @@
     
-ViewCompat.setBackground(tab.view, background);
+try %7B%0A            getBaseBackgroundDrawableField().set(tab.view, background);%0A            tab.view.invalidate();%0A            tab.parent.invalidate();%0A        %7D catch (IllegalAccessException e) %7B%0A            Timber.tag(TAG)%0A                    .d(e, %22Error setting the background for a Tab%22);%0A        %7D catch (NoSuchFieldException e) %7B%0A            Timber.tag(TAG)%0A                    .d(e, %22Error setting the background for a Tab%22);%0A        %7D%0A
 %0A   
@@ -1323,24 +1323,42 @@
 int tint) %7B%0A
+        try %7B%0A    
         Draw
@@ -1368,38 +1368,44 @@
 e bkg = 
-tab.view.
+(Drawable) 
 getBa
+seBa
 ckground
 ();%0A    
@@ -1392,28 +1392,59 @@
 seBackground
-();%0A
+DrawableField().get(tab.view);%0A    
         if (
@@ -1454,24 +1454,28 @@
  != null) %7B%0A
+    
             
@@ -1519,32 +1519,36 @@
 ();%0A            
+    
 DrawableCompat.s
@@ -1574,16 +1574,20 @@
         
+    
 %7D%0A      
@@ -1588,16 +1588,20 @@
         
+ 
+   
 setBackg
@@ -1629,206 +1629,874 @@
     
-return tab;%0A    %7D%0A%0A    @NonNull%0A    public static TabLayout.Tab setVisibility(@NonNull final TabLayout.Tab tab, final int visibility) %7B%0A        tab.view.setVisibility(visibility);%0A        return tab
+%7D catch (IllegalAccessException e) %7B%0A            Timber.tag(TAG)%0A                    .d(e, %22Error getting the background for a Tab%22);%0A        %7D catch (NoSuchFieldException e) %7B%0A            Timber.tag(TAG)%0A                    .d(e, %22Error getting the background for a Tab%22);%0A        %7D%0A%0A        return tab;%0A    %7D%0A%0A    @NonNull%0A    public static TabLayout.Tab setVisibility(@NonNull final TabLayout.Tab tab, final int visibility) %7B%0A        tab.view.setVisibility(visibility);%0A        return tab;%0A    %7D%0A%0A    private static Field getBaseBackgroundDrawableField() throws NoSuchFieldException %7B%0A        if (sBaseBackgroundDrawableField == null) %7B%0A            sBaseBackgroundDrawableField = TabLayout.TabView.class.getDeclaredField(%22baseBackgroundDrawable%22);%0A            sBaseBackgroundDrawableField.setAccessible(true);%0A        %7D%0A        return sBaseBackgroundDrawableField
 ;%0A  

fix TabLayoutUtils updating the background tint of tabs