1
Random myColor = new Random();
tv.setTextColor(Color.rgb(myColor.nextInt(255), myColor.nextInt(255), myColor.nextInt(255)));
string.xml:如何在android中隨機設置文字顏色?
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score"
android:textColor="@color/yellow"
/>
這將循環,我想每一個score
文本有不同的顏色。但它不工作
不要在這個問題的答案SO後幫你? http://stackoverflow.com/questions/5280367/android-generate-random-color-on-click – CubeJockey
什麼不工作? – Blackbelt
不要這樣做,如果它與背景顏色相同,將無法看到文字。而是製作一個預定義列表,並從列表中隨機選擇一個列表 –