您可以簡單地創建color.xml顏色的排列和選擇一個隨機的顏色由它來設置顏色的ActionBar以及狀態欄的顏色。
color.xml
<array name="actionbar_color">
<item>@color/bright_pink</item>
<item>@color/red</item>
<item>@color/orange</item>
<item>@color/yellow</item>
<item>@color/chartreuse</item>
<item>@color/green</item>
<item>@color/spring_green</item>
<item>@color/cyan</item>
<item>@color/azure</item>
<item>@color/blue</item>
<item>@color/violet</item>
<item>@color/magenta</item>
</array>
在你的活動
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// further code
int[] actionbarColor = context.getResources().getIntArray(R.array.actionbar_color);
actionBar.setBackgroundDrawable(new ColorDrawable(getRandom(actionbarColor)));
}
public int getRandom(int[] array) {
int rnd = new Random().nextInt(array.length);
return array[rnd];
}
你想改變顏色每次活動拿開還是什麼? –
@SwapnilMeshram是的,正好 –