material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

[TabLayout] background drawable not set correctly #1029

Closed CodeRedDev closed 4 years ago

CodeRedDev commented 4 years ago

Description: When setting android:background to a ShapeDrawable the set color in this drawable will not be inflated correctly everytime. In the example app provided below you'll even see it working correctly only once. This seems to have something to do with drawables I think, because if background is set to a color it will work as expected.

Expected behavior: The set drawable should be correctly inflated.

Source code: https://github.com/CodeRedDev/TabLayout-Background-Error

Android API version: 28

Material Library version: 1.1.0 (also tested with 1.2.0-alpha04)

Device: HTC U11+ API 28

ymarian commented 4 years ago

Hi @CodeRedDev,

Seems we are mutating your drawable when you use it for both background and tabIndicator. Can you duplicate the resource and use two different references?

ymarian commented 4 years ago

I sent a fix https://github.com/material-components/material-components-android/commit/bbd645a34179b643ed9d096cdf5dfd4ca1710d0f

for the root cause

CodeRedDev commented 4 years ago

Yeah the quick fix seems to work. Thank you very much. I also learned something pretty interesting from this issue about drawables :)