title: How to get drawable resources on FAB in Android
body: <p>I am trying to use a FAB with Bottom NavigationView in my app. I have designed drawable xml resources for that FAB to give the FAB gradient color and an icon along with a drop shadow of custom color. But the problem is when I try to get the drawable xml resource on FAB background attribute it doesn't work and the app crash. I am using <strong>Android Studio version 4.2.2</strong> with <strong>Android Gradle plugin version 4.1.3</strong> and <strong>Gradle Version 6.7.1</strong>.</p>
  <p><strong>Code for FAB with Bottom Navigation View</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.coordinatorlayout.widget.CoordinatorLayout
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:clipChildren=&quot;false&quot;
      android:clipToPadding=&quot;false&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;com.google.android.material.bottomappbar.BottomAppBar
          android:id=&quot;@+id/bottomAppBar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_gravity=&quot;bottom&quot;
          app:fabCradleMargin=&quot;5dp&quot;
          android:clipChildren=&quot;true&quot;
          android:clipToPadding=&quot;true&quot;
          app:fabCradleVerticalOffset=&quot;10dp&quot;&gt;
  &lt;!--        app:fabCradleRoundedCornerRadius=&quot;10dp&quot;--&gt;
  
          &lt;com.google.android.material.bottomnavigation.BottomNavigationView
              android:id=&quot;@+id/bottomNavigationView&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              app:labelVisibilityMode=&quot;labeled&quot;
              app:itemIconSize=&quot;15dp&quot;
              android:background=&quot;@android:color/transparent&quot;
              app:itemBackground=&quot;@android:color/transparent&quot;
              app:itemTextAppearanceActive=&quot;@style/BottomNavigationView.Active&quot;
              app:itemTextAppearanceInactive=&quot;@style/BottomNavigationView&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              app:menu=&quot;@menu/scan_app_menu&quot; /&gt;
  
  &lt;!--android:background=&quot;@null&quot;--&gt;
  
      &lt;/com.google.android.material.bottomappbar.BottomAppBar&gt;
  
      &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id=&quot;@+id/fab&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:tint=&quot;@color/white&quot;
          android:src=&quot;@drawable/scanqr&quot;
          android:background=&quot;@drawable/gradient_color_for_scanning_btn&quot;
          app:layout_anchor=&quot;@id/bottomAppBar&quot;/&gt;
  
  
      &lt;FrameLayout
          android:id=&quot;@+id/fragment_container&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot; /&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  <p><strong>Drawable xml resource Code called: gradient_color_for_scanning_btn</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layer-list xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;item&gt;
          &lt;shape
              android:innerRadius=&quot;50dp&quot;
              android:shape=&quot;oval&quot;&gt;
  
              &lt;corners android:radius=&quot;10dp&quot; /&gt;
  
              &lt;gradient
                  android:startColor=&quot;#1fb8fc&quot;
                  android:angle=&quot;18&quot;
                  android:endColor=&quot;#0A5F8A&quot; /&gt;
  
          &lt;/shape&gt;
      &lt;/item&gt;
      &lt;item
          android:bottom=&quot;5dp&quot;
          android:left=&quot;5dp&quot;
          android:right=&quot;5dp&quot;
          android:top=&quot;5dp&quot;&gt;
          &lt;bitmap
              android:gravity=&quot;center&quot;
              android:src=&quot;@drawable/scanqr&quot; /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  <p><strong>My dependencies</strong></p>
  <pre><code>plugins {
      id 'com.android.application'
  }
  
  android {
      compileSdkVersion 30
  
      defaultConfig {
          applicationId &quot;com.kamranullah.bottomnavscanapp&quot;
          minSdkVersion 21
          targetSdkVersion 30
          versionCode 1
          versionName &quot;1.0&quot;
          vectorDrawables.useSupportLibrary = true
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
  }
  
  dependencies {
  
      implementation 'androidx.appcompat:appcompat:1.3.0'
      implementation 'com.google.android.material:material:1.3.0-alpha03'
      implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
      testImplementation 'junit:junit:4.+'
      androidTestImplementation 'androidx.test.ext:junit:1.1.3'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
  }
  </code></pre>
  <p><strong>Logcat Result:</strong></p>
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kamranullah.bottomnavscanapp/com.kamranullah.bottomnavscanapp.MainActivity}: **android.view.InflateException: Binary XML file line #40: Binary XML file line #40: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton**
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3320)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
      at android.app.ActivityThread.access$1100(ActivityThread.java:229)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:7410)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
   **Caused by: android.view.InflateException: Binary XML file line #40: Binary XML file line #40: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton**
      at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
      at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
      at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
      at com.kamranullah.bottomnavscanapp.MainActivity.onCreate(MainActivity.java:30)
      at android.app.Activity.performCreate(Activity.java:6904)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3267)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
      at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:7410) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
   **Caused by: android.view.InflateException: Binary XML file line #40: Error inflating class com.google.android.material.floatingactionbutton.FloatingActionButton**
      at android.view.LayoutInflater.createView(LayoutInflater.java:657)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
      at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
      at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
      at com.kamranullah.bottomnavscanapp.MainActivity.onCreate(MainActivity.java:30) 
      at android.app.Activity.performCreate(Activity.java:6904) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3267) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
      at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:7410) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
   **Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Constructor.newInstance(Native Method)**
      at android.view.LayoutInflater.createView(LayoutInflater.java:631)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
      at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
      at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
      at com.kamranullah.bottomnavscanapp.MainActivity.onCreate(MainActivity.java:30) 
      at android.app.Activity.performCreate(Activity.java:6904) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3267) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
      at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:7410) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
   **Caused by: android.content.res.Resources$NotFoundException: File res/drawable/gradient_color_for_scanning_btn.xml from drawable resource ID #0x7f070072**
      at android.content.res.Resources.loadDrawableForCookie(Resources.java:4287)
      at android.content.res.Resources.loadDrawable(Resources.java:4156)
      at android.content.res.Resources.loadDrawable(Resources.java:4006)
      at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
      at android.view.View.&lt;init&gt;(View.java:4249)
      at android.widget.ImageView.&lt;init&gt;(ImageView.java:150)
      at android.widget.ImageButton.&lt;init&gt;(ImageButton.java:85)
      at android.widget.ImageButton.&lt;init&gt;(ImageButton.java:81)
      at com.google.android.material.internal.VisibilityAwareImageButton.&lt;init&gt;(VisibilityAwareImageButton.java:47)
      at com.google.android.material.floatingactionbutton.FloatingActionButton.&lt;init&gt;(FloatingActionButton.java:207)
      at com.google.android.material.floatingactionbutton.FloatingActionButton.&lt;init&gt;(FloatingActionButton.java:201)
      at java.lang.reflect.Constructor.newInstance(Native Method) 
      at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
      at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) 
      at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) 
      at com.kamranullah.bottomnavscanapp.MainActivity.onCreate(MainActivity.java:30) 
      at android.app.Activity.performCreate(Activity.java:6904) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3267) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
      at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:7410) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
   **Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #10&lt;gradient&gt; tag requires 'angle' attribute to be a multiple of 45**
  </code></pre>
  <p><strong>What I want to achieve:</strong>
  <a href="https://i.stack.imgur.com/bflK0.jpg" rel="nofollow noreferrer">Needed is encircled with red line</a></p>