2016-08-27 8 views

答えて

0

単一の色を定義します。

<color name="white">#ffffff</color> 
<color name="black">#000000</color> 
<color name="green">#0dae68</color> 

は、配列を作成します。

<color-array name="colors"> 
    <item>@color/white</item> 
    <item>@color/black</item> 
    <item>@color/green</item> 
</color-array> 

はコードでそれを使用します。

int[] color = context.getResources().getIntArray(R.array.color); 

for (int i = 0; i < color.length; i++) { 
    paint.setColor(color[i]); 
    // Do something with the paint. 
} 
1

は、以下のことを試してみてください。

public int[] listColors = new int[10]; 

private void initColors() { 
    listColors[0] = getResources().getColor(R.color.color1); 
    listColors[1] = getResources().getColor(R.color.color2); 
    listColors[2] = getResources().getColor(R.color.color3); 
    . 
    . 
}  

button.setBackgroundColor(listColors[0]); 
. 
. 
0

あなたは次のようなものを探しているかもしれません:

public class MyColor{ 
    private String name; 
    private int red, green, blue; 

    // constructor, getters, setters 
} 

... 
List<MyColor> list = new ArrayList<MyColor>(); 
... 

MyColor color = list.get(position); 
button.setBackgroundColor(Color.rgb(color.getRed(), color.getGreen(), color.getBlue()));