Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display SVG Image in image view in android [duplicate]

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?

like image 849
Ivan Podhornyi Avatar asked Aug 21 '13 11:08

Ivan Podhornyi


2 Answers

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.

like image 152
Paul LeBeau Avatar answered Sep 19 '22 17:09

Paul LeBeau


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);
  }
}
like image 27
emilpmp Avatar answered Sep 20 '22 17:09

emilpmp