각 버튼은 사용자가 구성 할 수있는 데이터베이스에 저장된 색상이있는 클릭 가능한 것을 나타냅니다. 단추의 배경은 다음에 나오는 <shape>
입니다.드로어 블의 색상을 어떻게 동적으로 변경합니까 <shape>? (안드로이드)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#000" />
<corners android:radius="5dp" />
<gradient android:startColor="#FFF"
android:centerColor="#FFF"
android:endColor="#666"
android:angle="315" />
<padding android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
나는 <gradient>
요소에서 좀하고 싶습니다 - 특히 startColor
centerColor
및 endColor
속성. 나는 이것을 할 수있다 :
button.getBackground().setTint(theColor);
그러나 그것은 뇌졸중과 그라디언트를 쓸어 버릴 것 같다.
이것이 가능합니까? 더 좋은 방법이 있습니까? 조각 아래
이 방법을 사용해 보았습니다. ((GradientDrawable) button.getBackground()). setColor (theColor); ' – Ironman