I am trying to set icon of selected color to a preference:
Preference prf = (Preference) findPreference(\"SelectColorPref\");
prf.setIcon
the easiest way using ShapeDrawable
ShapeDrawable sdrawable = new ShapeDrawable(new RectShape());
sdrawable.paint.Color = color.RED;
sdrawable.setIntrinsicWidth(10);
sdrawable.setIntrinsicHeight(40);
You should be able to create a solid-colour Drawable using code similar to this:
Bitmap bm = BitmapFactory.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
Canvas cnv = new Canvas(bm);
int red = 0xff0000;
cnv.drawColor(red);
Drawable drawable = new BitmapDrawable(bm);
This will create a Drawable containing a 50x50 pixels red square.
(Please note that I haven't tested this code, but I use something similar in my code.)