Search code examples
androidandroid-appcompatandroid-themematerial-components-android

How to apply MaterialComponents only to some widget?


I am migrating from AppCompat to MaterialComponents, and I would like to keep some widgets (like the Bottom Navigation Bar) AppCompat-themed. However, when I want to apply MaterialComponents theming to Buttons and TextFields, I must set my app theme to MaterialComponents.... and therefore all my widgets are MaterialComponents-themed. How can I make only some widgets MaterialComponents-themed ? I have been looking for an answer on StackOverflow but couldn't find anything.


Solution

  • You can use Bridge themes like :

    Theme.MaterialComponents.Bridge
    Theme.MaterialComponents.Light.Bridge
    Theme.MaterialComponents.NoActionBar.Bridge
    Theme.MaterialComponents.Light.NoActionBar.Bridge
    Theme.MaterialComponents.Light.DarkActionBar.Bridge
    

    Bridge themes inherit from AppCompat themes, but also define the new Material Components theme attributes for you. If you use a bridge theme, you can start using Material Design components without changing your app theme. (From documentaion)

    Have a look : Get started - Material Design