How to put a background color on a Shapedrawable?

Asked

Viewed 31 times

1

It seems to be something very simple, but I’m only able to put the color of the border, someone knows? Follow 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);
}

1 answer

0

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

ShapeDrawable drawable = new ShapeDrawable();
drawable.getPaint().setColor(getResources().getColor(R.color.blue));
getActionBar().setBackgroundDrawable(drawable);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.