Create the GradientDrawable class as follows:
public class RoundedDrawable extends GradientDrawable { public RoundedDrawable(int shape, int solidColor, int strokeWidth, int strokeColor, float[] fourRadii) { this.mutate(); this.setShape(shape); this.setColor(solidColor); this.setStroke(strokeWidth, strokeColor); this.setCornerRadii(fourRadii); } }
Now use this in your activity as follows:
public class AAActivity extends the action {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_transaction_layout); RoundedDrawable customBg; RelativeLayout relList = (RelativeLayout) findViewById(R.id.relList); float radii[]={5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f}; customBg = new RoundedDrawable(GradientDrawable.RECTANGLE,Color.parseColor("#FFFFFF"), 2, Color.parseColor("#8C8C8C"),radii); relList.setBackgroundDrawable(customBg); LinearLayout linearItemsRow = (LinearLayout) findViewById(R.id.linearItemsRow); float[] rowRadii={5.0f, 5.0f, 5.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f}; customBg = new RoundedDrawable(GradientDrawable.RECTANGLE,Color.parseColor("#CBCBCB"), 0, 0, rowRadii); linearItemsRow.setBackgroundDrawable(customBg); }
}
Hope this helps.
source share