Reputation: 71
I just want to see some SVG images, when i click on the app. I tried it. The steps to import into android studio was correct. But when i run the apk, i can see only a blank screen. The SVG image did'nt show up. So what can i do? How can i correct it? The code i used is,
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGParser;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a new ImageView
ImageView imageView = new ImageView(this);
// Set the background color to white
imageView.setBackgroundColor(Color.BLACK);
// Parse the SVG file from the resource
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
// Get a drawable from the parsed SVG and set it as the drawable for the ImageView
imageView.setImageDrawable(svg.createPictureDrawable());
// Set the ImageView as the content view for the Activity
setContentView(imageView);
}
Upvotes: 0
Views: 2194
Reputation: 101800
Your problem is likely caused by one of these two things:
See: Having issue on Real Device using vector image in android. SVG-android
Upvotes: 1