Search code examples
androidfloating-action-buttonmaterial-components-android

ExtendedFloatingActionButton without using MaterialComponentTheme


I want to use ExtendedFloatingActionButton but I don't want to apply activity wide MaterialComponent themes because I have existing buttons with custom backgrounds and icons and I'll need to modify those for material themes. I tried using MaterialComponent Bridge themes but ExtendedFloatingActionButton doesn't work with bridge theme. It's not rendered properly.


Solution

  • Fixed it by explicitly applying style to the ExtendedFloatingActionButton while using the bridge theme for activity.

    <activity
          android:name=".ui.activity.ActivityName"
          android:screenOrientation="portrait"
          android:theme="@style/AppThemeMaterial.NoActionBar">
    

    while AppTheme material is

    <style name="AppThemeMaterial" parent="Theme.MaterialComponents.Light.Bridge" />
    

    You can use any of the bridge themes. Finally, applied the ExtendedFloatingActionButton theme explicitly.

     <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
             android:id="@+id/fab"
             style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
             ... 
    />