How to create android shape background programmatically?

前端 未结 5 1714
无人共我
无人共我 2020-12-13 03:35

How to create this shape programmatically?




        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 04:16

    If you want to Create

    Rounded drawable with Gradient

    then use below code.

    public static GradientDrawable generateGradientBackgroundCircular(String topColor, String bottomColor) {
        int[] colors = {Color.parseColor(topColor), Color.parseColor(bottomColor)};
    
        //create a new gradient color
        GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TL_BR, colors);
        gd.setShape(GradientDrawable.OVAL);
    
        return gd;
    }
    

提交回复
热议问题