28

I use svg-android.jar from https://github.com/pents90/svg-android at its work fine but only on emulator devices in eclipse. Agrrrr. On real devices it just empty imageView on screen. here is my code:

SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.test);
Drawable drawable = svg.createPictureDrawable();
imgView.setImageDrawable(drawable);

any suggestion?

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Ivan Podhornyi
  • 779
  • 3
  • 7
  • 17

2 Answers2

46

On newer devices that have hardware rendering turned on by default, you need to explicitly turn on software rendering.

imgView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

I suspect this is probably your problem.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
1

Use AppCompatImageView instead ImageView in xml like the below code

<android.support.v7.widget.AppCompatImageView
    android:tint="#d74313"
    app:srcCompat="@drawable/circle_icon"
    android:layout_width="30sp"
    android:layout_height="30sp" />

and in your build.gradle

android {
  defaultConfig {
    vectorDrawables {
      useSupportLibrary = true
    }
  }
}

If the above doesn't work, try this also in your application class

public class App extends Application {

  @Override public void onCreate() {
    super.onCreate();
    // Make sure we use vector drawables
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
  }
}
crgarridos
  • 8,758
  • 3
  • 49
  • 61
emilpmp
  • 1,716
  • 17
  • 32