1

有没有办法从使用它的 xml 设置已定义的可绘制资源的属性。考虑以下示例:

假设我们有一个可绘制的 xml 文件,一个名为“orange_btn”的形状说:

<?xml version="1.0" encoding="UTF-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/ripe_orange"/>

    <corners android:bottomRightRadius="16dp" android:bottomLeftRadius="16dp"
    android:topLeftRadius="16dp" android:topRightRadius="16dp"/>
</shape>

并假设我们有一些包含图像按钮的布局 xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

<ImageView android:id="@+id/clouds"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:src="@drawable/orange"/>

</RelativeLayout>

假设我想更改其中一个形状属性,例如布局 xml 中的角半径,我该怎么做?

4

0 回答 0