私はこのようなlayout.xmlを介して定義されたいくつかのボタンを含むアプリケーションに取り組んでいます
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/largebutton" >
</Button>
@ drawable/largebuttonは次のようになります
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <gradient android:startColor="@color/menu_button_active_start" android:endColor="@color/menu_button_active_end" android:angle="270" />
            <stroke android:width="@dimen/largebutton_stroke" android:color="@color/menu_button_stroke" />
            <corners android:radius="@dimen/largebutton_radius" />
            <padding android:left="@dimen/largebutton_padding_leftright" android:top="@dimen/largebutton_padding_topbottom" android:right="@dimen/largebutton_padding_leftright" android:bottom="@dimen/largebutton_padding_topbottom" />
        </shape>
    </item>
    <item android:state_focused="true" >
        <shape>
            <gradient android:startColor="@color/menu_button_focused_start" android:endColor="@color/menu_button_focused_end" android:angle="270" />
            <stroke android:width="@dimen/largebutton_stroke" android:color="@color/menu_button_focused_stroke" />
            <corners android:radius="@dimen/largebutton_radius" />
            <padding android:left="@dimen/largebutton_padding_leftright" android:top="@dimen/largebutton_padding_topbottom" android:right="@dimen/largebutton_padding_leftright" android:bottom="@dimen/largebutton_padding_topbottom" />
        </shape>
    </item>
 .....
</selector>
異なる状態のグラデーションカラーを除いて、パディング、ストローク、半径などのすべてのプロパティは同じです。私の問題は、私のアプリケーションがより多くのスタイルを持たなければならないということです。色のリストがあり、1つのアプリケーションを選択すると、すべての色が選択した色に変わるので、想像できます。したがって、20色の場合、20の異なるxmlは正しい方法ではありません。
すべてのandroid:statesのstartColor値とendColor値の両方がWebからダウンロードされ、DBに保存されますが、それらがいくつあるかはわかりません。
この動作を実現する方法はありますか?私はすべてのフォーラムを検索しましたが、ほとんどの回答は不可能であるというものでした。私はcolors.xmlを上書きする1つの「解決策」を見つけましたが、それは私にとって最良の解決策ではないようです。
だから私の質問は、colors.xmlの色を動的に変更できますか?このようなもの
List<Colors> colors = downloadColorsFromWeb();
Button b = new Button;
b.setDrawable(drawable.with(colors));
よろしくお願いします。
nosko。