2011-07-13 116 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);