美文网首页
使用代码实现Shape

使用代码实现Shape

作者: AndroidPool | 来源:发表于2017-04-29 02:55 被阅读0次

    xml代码

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/white" />
    
        <corners android:radius="5dp" />
    
        <stroke
            android:width="1dp"
            android:color="@color/questionBankLightPurple" />
    </shape>
    

    Java代码:

    获取得drawable,发现其实返回的是一个 android.graphics.drawable.GradientDrawable;

    /**
     * 产生shape类型的drawable
     *
     * @param solidColor
     * @param strokeColor
     * @param strokeWidth
     * @param radius
     * @return
     */
    public static GradientDrawable getDrawable(int solidColor, int strokeColor, int strokeWidth, float radius) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(solidColor);
        drawable.setStroke(strokeWidth, strokeColor);
        drawable.setCornerRadius(radius);
        return drawable;
    }
    

    相关文章

      网友评论

          本文标题:使用代码实现Shape

          本文链接:https://www.haomeiwen.com/subject/ocfzzttx.html