How to put a background color on a ShapeDrawable?

1

It seems to be something very simple, but I can only put the color of the border, does anyone know? Here is the code I'm using:

public void borda(View view) {
    float[] outerR = new float[] {10, 10, 10, 10, 10, 10, 10, 10};
    RectF   inset = new RectF(6, 6, 6, 6);
    float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
    ShapeDrawable sd = new ShapeDrawable();
    sd.setShape(new RoundRectShape(outerR, null, null));
    sd.getPaint().setColor(Color.LTGRAY);
    sd.getPaint().setStrokeWidth(3f);
    //sd.setPadding(20, 20, 20, 20);
    sd.getPaint().setStyle(Style.STROKE);
    view.setBackground(sd);
}
    
asked by anonymous 12.08.2015 / 22:02

1 answer

0

If you just want to insert a color, this is the shortest path:

ShapeDrawable drawable = new ShapeDrawable();
drawable.getPaint().setColor(getResources().getColor(R.color.blue));
getActionBar().setBackgroundDrawable(drawable);
    
13.08.2015 / 02:22