2011-05-06 145 views
1

我想將背景顏色設置爲「白色」,但是它是黑色的。我該怎麼做呢?我嘗試了這種方式:如何將背景顏色設置爲白色

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    View someView = findViewById(R.id.myScreen); 

    // Find the root view 
    View root = someView.getRootView(); 

    // Set the color 
    root.setBackgroundColor(android.R.color.white); 
} 

和main.xml中的文件是...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/myScreen" > 

    <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button" android:text="Play Sound"></Button> 
</LinearLayout> 
+0

我想你忘了粘貼您的XML文件。請向我們展示您的XML文件,以便我們可以幫助您。 – Varundroid 2011-05-06 11:13:45

回答

1

使用

root.setBackgroundColor(Color.WHITE); 

,而不是android.R.color.white

+0

確定爲我工作 – SRam 2011-05-06 11:25:35

2

簡單的設置android:background="#ffffff"在你的LinearLayout 。

+0

謝謝..工作 – SRam 2011-05-06 11:23:04

+0

你應該接受答案,如果你認爲它對你有幫助,upvote太.... :) – 2011-05-06 11:57:08

3

是嘗試這種root.setBackgroundColor(Color.WHITE);

+0

謝謝很多解決.. .. – SRam 2011-05-06 11:22:16