I am unable to set a vector drawable xml as background in an Android activity.
I tried to set it as background by setting
to the Coordinator layout root of my activity.
to the Coordinator layout child Constraint layout
ImageViewchild of the
None of the above approaches worked. I can see only a black screen in the design preview, and my application crashes with a Fatal exception:
android.view.InflateException: Binary XML file line #5: Error inflating class android.support.design.widget.CoordinatorLayout
Here is an outline of my layout:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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="match_parent" android:background="@drawable/test_background" android:fitsSystemWindows="true" android:orientation="vertical" android:scrollbarStyle="outsideOverlay"> <android.support.constraint.ConstraintLayout> <android.support.v7.widget.AppCompatImageView> </android.support.v7.widget.AppCompatImageView> </android.support.constraint.ConstraintLayout> </android.support.design.widget.CoordinatorLayout>
The test_background drawable is an xml vector asset created from a png image, converted to an svg in Inkscape, and exported into an xml asset via an Inkscape plugin. The png image contains a kind of pattern, and I never really transformed anything on it to a path. So it looks like this:
<vector xmlns:ns0="http://schemas.android.com/apk/res/android" ns0:name="svg869" ns0:width="1382.2272dp" ns0:height="2073.3408dp" ns0:viewportWidth="666.666666667" ns0:viewportHeight="1000.0"/>
However, I did confirm that the plugin is exporting the xml successfully because I can set the xml background successfully as an icon (for example as a logo/icon).
My problem is that I cannot set the vector as background.
Are there any attributes that I need to set within the drawable in order to use it as background for an activity? Or am I doing something wrong?
Thanks a lot for any help!