• 7

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am unable to set a vector drawable xml as background in an Android activity.

I tried to set it as background by setting android:background="@drawable/test_background"

  • to the Coordinator layout root of my activity.

  • to the Coordinator layout child Constraint layout

  • to an ImageView child of the ConstraintLayout via app:srcCompat"= @drawable/test_background"

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"?>




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"

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!

As described here you must create a new layer drawable to hold vector drawable. This implementation is for Pre-Lollipop devices. Devices with Lollipop and above don't need this. I've tested it and it works i.e irrespective of the type of rootview you have.

  • 1
Reply Report
      • 2
    • This does not work. I tried the example with my own vector and it crashes on Android 4.1. When I remove the background field, everything is ok.

You need to convert your SVG into an Android Vector Asset. You can easily do this with Android Studio. Right click your project > New > Vector Asset. Then Select "Local File" and enter the file location/path

enter image description here enter image description here

  • 0
Reply Report