2011-03-20 81 views
0

下面的代碼將背景顏色更改爲黑色,無論我以何種顏色通過 參數。如何在運行時在Android中更改Button的BackgroundColor?

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    b = (Button)findViewById(R.id.Button01); 
    b.setBackgroundColor(R.color.red); 
} 

任何幫助?

回答

0

使用本:

getResources().getColor() 

類似如下:

b.setBackgroundColor(getResources().getColor(R.color.red)); 
0

我知道,它確實是一個遲到的回答,但我只是你的問題遇到了

可以使用

b.setBackgroundColor(android.R.color.white) 

b.setBackgroundColor(Color.RED); 
相關問題