我想在对话框中设置一个ListView中背景为白色,文本为黑色。下面的代码生成一个对话框,是一个黑色的背景带有黑色的字体。但是contextmenu看起来是正确的,有白色背景和黑色字体。
我把主题设置为Light,还要添加什么呢?
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);
你可以使用一个自定义的适配器:
getView(int position, View v, ViewGroup parent)
然后你可以在每一个 list item中调用 setBackgroundColor() / setBackgroundDrawable() / setBackgroundResource()
你new的是简单适配器,想要给ListView写样式的话,可以重写一个ListView的适配器,让适配器继承BaseAdapter,在getView方法里写ListItem的样式,可以直接在getView方法里写set各种样式。