Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FloatingActionButton + VectorDrawable crashing on pre-Lollipop

After some research I noticed that the FloatingActionButton of com.android.support:design:23.3.0 crashes with the use of SVG on android:src. The SVG was get from the Android Studio assets.

It crashes on Android <= 4.4. On 5.0 it works perfectly.

SVG:

ic_keyboard_voice_white_24dp

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFF"
        android:pathData="M12,15c1.66,0 2.99,-1.34 2.99,-3L15,6c0,-1.66 -1.34,-3 -3,-3S9,4.34 9,6v6c0,1.66 1.34,3 3,3zM17.3,12c0,3 -2.54,5.1 -5.3,5.1S6.7,15 6.7,12L5,12c0,3.42 2.72,6.23 6,6.72L11,22h2v-3.28c3.28,-0.48 6,-3.3 6,-6.72h-1.7z"/>
</vector>

XML:

  <android.support.design.widget.FloatingActionButton
      android:id="@+id/fab_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_marginBottom="20dp"
      android:layout_centerHorizontal="true"
      app:backgroundTint="@color/colorAccentSecondary"
      app:fabSize="normal"
      app:elevation="1dp"
      android:src="@drawable/ic_keyboard_voice_white_24dp"/>

Gradle:

defaultConfig {
  ...
  vectorDrawables.useSupportLibrary = true
}

Stacktrace: https://gist.github.com/ppamorim/420dba3e9dc3022a86a3a1f50400d7d0

Is this a bug? I solved this problem with ImageView using AppCompatImageView. Any workaround for this problem with FloatingActionButton?

like image 315
Pedro Paulo Amorim Avatar asked Feb 08 '23 00:02

Pedro Paulo Amorim


1 Answers

If you want to use VectorDrawables on pre-Lollipop devices, you need to be using at least the 23.2.0 version of the Support Library, and you need to reference the VectorDrawble using

app:srcCompat="@drawable/my_vector_drawable"

http://android-developers.blogspot.co.nz/2016/02/android-support-library-232.html

like image 105
Paul LeBeau Avatar answered Feb 11 '23 16:02

Paul LeBeau