1

私はImageButton自分のアプリケーションのレイアウトを持っていて、これの角を丸くしたいImageButtonので、次のようなスタイルを使用しています:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dp"
        android:color="@android:color/black" />
    <corners android:radius="15dp" />
    <solid android:color="@android:color/black"/>
</shape>

そして、私は使用していますandroid:background="@drawable/my_rounded_shape.xml"/>

問題は、この後、背景色を黒からカスタム色に変更したいのですが、プログラムでスタイルを変更できず、コーナーで新しいスタイルを生成する方法がありませんが、別の色でImageButton.

それを行う方法または回避策があることを明確にしていただけますか?

4

2 に答える 2

0

しばらくして、私の場合の解決策を思いつきました-私のJavaコードでは、次のようなことをします:

GradientDrawable drawable = (GradientDrawable) imageButton.getBackground();
drawable.setColor(color);

これにより、「形状」に記述されている丸みを帯びた角を保存し、同時に背景色を変更できます。

于 2014-10-06T08:50:44.880 に答える