I am trying to programmatically create a ShapeDrawable, but the following code shows nothing.
ImageView image = new ImageView (context); image.setLayoutParams (new LayoutParams (200, 200)); ShapeDrawable badge = new ShapeDrawable (new OvalShape()); badge.setBounds (0, 0, 200, 200); badge.getPaint().setColor(Color.RED); ImageView image = new ImageView (context); image.setImageDrawable (badge); addView (image);
I can make it work with xml.
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="200px" android:height="200px" /> <solid android:color="#F00" /> </shape> ImageView image = new ImageView (context); image.setLayoutParams (new LayoutParams (200, 200)); image.setImageResource (R.drawable.badge); addView (image);
But I would like to create it programmatically. Xml works fine, so the problem cannot be with ImageView, it should be in creating ShapeDrawable.
source share