我有以下xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#000000" />
<solid android:color="#000000" />
</shape>
</item>
<item android:top="0dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#414141" />
<solid android:color="#414141" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#2C2C2C" />
<solid android:color="#2C2C2C" />
</shape>
</item>
</layer-list>
这正是我想要的,但我无法使用它。我想在运行时更改三个图层的颜色,所以我必须完全以编程方式完成。我知道我必须使用LayerDrawable但我不知道如何实现相当于android:top和android:bottom。有人可以帮帮我吗?
答案 0 :(得分:0)
ImageView imageView1 = (ImageView) findViewById(R.id.imgView1);
((GradientDrawable ) imageView1.getBackground()).setColorFilter(
Color.RED, PorterDuff.Mode.SRC_ATOP);