Tag: xml drawable

在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中,我不介意。