DeweyReed / Theme

🎨 An Experimental Theme Engine for Android
Apache License 2.0
93 stars 6 forks source link

Theme breaks MaterialButton in library modules. #9

Closed DeweyReed closed 4 years ago

DeweyReed commented 4 years ago

Even if I've disabled Theme in the edit mode, Theme still breaks MaterialButton in library modules. In the application mode, everything works fine. What's going on?

DeweyReed commented 4 years ago

It turns out that the library module doesn't include Theme dependency, and then it doesn't know how to inflate <Button> to a MaterialButton.

Solution 1: Include Theme in every module or use api in the base module.

Solution 2: Define AppTheme.LibraryPreview and use it in library modules, use AppTheme in the app module, and add tools:replace="android:theme" to the manifest.

    <style name="AppTheme.LibraryPreview">
        <item name="viewInflaterClass">
            com.google.android.material.theme.MaterialComponentsViewInflater
        </item>
    </style>