2014-02-17 51 views

回答

0

在活動時間你

Button btn = findViewById(R.id.myButtonId); 

找到您的按鈕,並設置具有不同的背景顏色按鈕的背景顏色這樣

int color = // generate some random color 
btn.setBackgroundColor(color); 
0

您可以使用隨機()爲了設置背景顏色按鈕。

例如:

int[] color={Color.RED,Color.BLACK,Color.GREEN}; 

    onCreate() 
    { 
    Button b=(Button)findViewById(R.id.button1); 

    Random random=new Random(); 

    b.setBackgroundColor(color[random.nextInt(3)]); 

    } 
相關問題