动态设置drawable中xml样式的值

Posted by アライさん on 2019年10月22日

seekbar_thumb.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="100dp"
android:height="30dp" />

<solid android:color="#2db334" />
<corners
android:radius="20dp"
/>
</shape>
```

代码设置drawable里的值
```java
GradientDrawable drawable = (GradientDrawable)getResources().getDrawable(R.drawable.seekbar_thumb);
drawable.setSize(100,30);