Search code examples
androidmaterial-designfloating-action-buttonandroid-coordinatorlayoutandroidx

how can implement Extended Floating Action Button in android


So many references explain about extended-floating-action-button

with Material Components libarary

for use this feature must merge android studio with androidx and add

 implementation 'com.google.android.material:material:1.1.0-alpha04'

library >= 4 and must put extended-floating-action-button in CooordinatoriLayout

i do everything right and past from so many issues like

The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

but fixed with changing parent style with

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

now i see extended-floating-action-button in layout correctly enter image description here

but still cant use implement Extended Floating Action Button and when run project got this error Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton

with description The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

i do so many research about this but there is no good and complete reference or tutorial and i am wonder any one in the world could use this feature ?

this is what i want

UPDATED

problem came from parent layout! android:theme="@style/AppTheme" must be added in parent layout


Solution

  • You are using the appcompat theme in your layout with styles.xml like this

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    

    change it to these lines

    <style name="AppTheme" parent="Theme.MaterialComponents">
    

    after that, you import that style in your layout

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:orientation="vertical"
    android:theme="@style/AppTheme"//here is the xml layout root tag>
    

    Sorry I Forgot the main thing

    <application
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    

    you also have to do this. and don't use appcompat and material theme in the same layout, please