Setting a vector as the background of a FAB
I have a problem getting to display a vector or mipmap as the background of a Floating Action Button. Does anyone know what might be going wrong here?
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/nationality" app:srcCompat="@drawable/flag_united_states_of_america_" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:backgroundTint="@android:color/transparent" android:layout_alignParentRight="true" />
vector:
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="512dp" android:height="512dp" android:viewportWidth="512" android:viewportHeight="512"> <path android:pathData="M256,256m-256,0a256,256 0,1 1,512 0a256,256 0,1 1,-512 0" android:fillColor="#F0F0F0"/> <path android:pathData="M244.87,256H512c0,-23.106 -3.08,-45.49 -8.819,-66.783H244.87V256z" android:fillColor="#D80027"/> <path android:pathData="M244.87,122.435h229.556c-15.671,-25.572 -35.708,-48.175 -59.07,-66.783H244.87V122.435z" android:fillColor="#D80027"/> <path android:pathData="M256,512c60.249,0 115.626,-20.824 159.356,-55.652H96.644C140.374,491.176 195.751,512 256,512z" android:fillColor="#D80027"/> <path android:pathData="M37.574,389.565h436.852c12.581,-20.529 22.338,-42.969 28.755,-66.783H8.819C15.236,346.596 24.993,369.036 37.574,389.565z" android:fillColor="#D80027"/> <path android:pathData="M118.584,39.978h23.329l-21.7,15.765l8.289,25.509l-21.699,-15.765L85.104,81.252l7.16,-22.037C73.158,75.13 56.412,93.776 42.612,114.552h7.475l-13.813,10.035c-2.152,3.59 -4.216,7.237 -6.194,10.938l6.596,20.301l-12.306,-8.941c-3.059,6.481 -5.857,13.108 -8.372,19.873l7.267,22.368h26.822l-21.7,15.765l8.289,25.509l-21.699,-15.765l-12.998,9.444C0.678,234.537 0,245.189 0,256h256c0,-141.384 0,-158.052 0,-256C205.428,0 158.285,14.67 118.584,39.978zM128.502,230.4l-21.699,-15.765L85.104,230.4l8.289,-25.509l-21.7,-15.765h26.822l8.288,-25.509l8.288,25.509h26.822l-21.7,15.765L128.502,230.4zM120.213,130.317l8.289,25.509l-21.699,-15.765l-21.699,15.765l8.289,-25.509l-21.7,-15.765h26.822l8.288,-25.509l8.288,25.509h26.822L120.213,130.317zM220.328,230.4l-21.699,-15.765L176.93,230.4l8.289,-25.509l-21.7,-15.765h26.822l8.288,-25.509l8.288,25.509h26.822l-21.7,15.765L220.328,230.4zM212.039,130.317l8.289,25.509l-21.699,-15.765l-21.699,15.765l8.289,-25.509l-21.7,-15.765h26.822l8.288,-25.509l8.288,25.509h26.822L212.039,130.317zM212.039,55.743l8.289,25.509l-21.699,-15.765L176.93,81.252l8.289,-25.509l-21.7,-15.765h26.822l8.288,-25.509l8.288,25.509h26.822L212.039,55.743z" android:fillColor="#0052B4"/> </vector>
implementations:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.appcompat:appcompat:1.2.0-rc01' implementation 'androidx.appcompat:appcompat-resources:1.2.0-rc01' implementation 'com.google.android.material:material:1.3.0-alpha01'
results:
How it looks in the viewer in Android Studio
How it looks in the emulator
Just set maxImageSize to 56dp in the xml of the FLoating Action Button:
app:maxImageSize="56dp"