2016-08-02 12 views
0

enter image description here卡視圖rendom彩色像上述圖像中的機器人工作室

卡視圖隨機顏色像在機器人工作室上方的圖像。如果有更多的卡項目不是繼續色序

+1

這將生成隨機顏色代碼http://stackoverflow.com/questions/5280367/android-generate-random-color-on-click所以你可以分配該卡的顏色代碼 –

+0

它的工作@Surya Bondada –

+0

@ Payal Sorathiya歡迎。你現在可以投票給我的評論。 –

回答

2

定義你選擇這樣的顏色在colors.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <item name="blue" type="color">#FF33B5E5</item> 
    <item name="purple" type="color">#FFAA66CC</item> 
    <item name="green" type="color">#FF99CC00</item> 
    <item name="orange" type="color">#FFFFBB33</item> 
    <item name="red" type="color">#FFFF4444</item> 

    <integer-array name="androidcolors"> 
     <item>@color/blue</item> 
     <item>@color/purple</item> 
     <item>@color/green</item> 
     <item>@color/orange</item> 
     <item>@color/red</item> 
    </integer-array> 

</resources> 

要隨機化的顏色選擇,你可以使用下面的代碼:
int[] androidColors = getResources().getIntArray(R.array.androidcolors); int randomAndroidColor = androidColors[new Random().nextInt(androidColors.length)]; view.setBackgroundColor(randomAndroidColor);