How to make a Drawable object with my selected color in code

后端 未结 2 895
眼角桃花
眼角桃花 2021-01-26 03:08

I am trying to set icon of selected color to a preference:

Preference prf = (Preference) findPreference(\"SelectColorPref\");

prf.setIcon

2条回答
  •  [愿得一人]
    2021-01-26 03:53

    the easiest way using ShapeDrawable

     ShapeDrawable sdrawable = new ShapeDrawable(new RectShape());
     sdrawable.paint.Color = color.RED;
     sdrawable.setIntrinsicWidth(10);
     sdrawable.setIntrinsicHeight(40);
    

提交回复
热议问题