在xml相同的代码中以编程方式绘制的形状
我有以下的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
对象?
我尝试没有成功(Kotlin):
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;