形状绘制编程
问题描述:
我有以下XML:形状绘制编程
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/coral_seconds"/>
<size
android:height="24dp"
android:width="24dp"/>
</shape>
如何使这个XML作为programatical Drawable
oject?
我尝试没有成功(科特林):
val circle = ShapeDrawable(OvalShape())
circle.paint.color = ContextCompat.getColor(context, resId)
circle.paint.style = Paint.Style.FILL;
答案可以在Java中,我不介意。
答
貌似尺寸可以简单地由intrinsicDIMEN
值等设定:
val circle = ShapeDrawable(OvalShape())
circle.intrinsicHeight = dpi24
circle.intrinsicWidth = dpi24
circle.paint.color = ContextCompat.getColor(context, resId)
circle.paint.style = Paint.Style.FILL;