2011-07-13 122 views
1

我想在對話框中設置ListView的背景爲白色,文本爲黑色。以下代碼在黑色背景上生成黑字的對話框。我的contextmenu看起來正確與白色背景上的黑色字。Android對話框,黑色背景上的黑色文本?

 dialog1 = new Dialog(this);   
     AlertDialog.Builder builder = new AlertDialog.Builder(this);    
     builder.setTitle("Select Color Mode"); 

     ListView modeList = new ListView(this);   
     String[] stringArray = new String[] { "Bright Mode", "Normal Mode" }; 
     ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray); 
     modeList.setAdapter(modeAdapter); 

我是否錯過了什麼?

只需添加,我將主題設置爲Light。

+0

hmm ..我想我們可以通過擴展基本適配器來自定義列表行的視圖。在那裏你可以決定應該是什麼背景和前景色。 –

回答

1

你必須使用一個自定義適配器:

getView(int position, View v, ViewGroup parent)

然後可以調用setBackgroundColor()/setBackgroundDrawable()/setBackgroundResource()每個列表項

1

快速更改列表視圖的背景色:

dialog1.getListView().setBackgroundColor(Color.WHITE);