我有以下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作为一个初级Drawable
对象?
我没有成功(Kotlin):
val circle = ShapeDrawable(OvalShape())
circle.paint.color = ContextCompat.getColor(context, resId)
circle.paint.style = Paint.Style.FILL;
答案可以是Java,我不介意。
答案 0 :(得分:1)
看起来大小可以通过intrinsicDIMEN
值设置,例如:
val circle = ShapeDrawable(OvalShape())
circle.intrinsicHeight = dpi24
circle.intrinsicWidth = dpi24
circle.paint.color = ContextCompat.getColor(context, resId)
circle.paint.style = Paint.Style.FILL;