有谁知道如何以编程方式从字符串数组中设置列表项的背景?我有两个字符串数组,一个是文本视图的标题,另一个包含颜色参考。我已将标题数组添加到数组适配器中,并且正在显示,但现在我想更改数组中每个项目的背景颜色
这是我的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
>
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="18dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center" />
</RelativeLayout>
继承人我的代码到目前为止
ListView menuList = (ListView) findViewById(R.id.listView1);
String[] items = {"menuItem1","menuItem2","menuItem3","menuItem4","menuItem4","menuItem5","menuItem6","menuItem7","menuItem8"};
String[] colors = {"#ffffff","#000000","#ffffBB","#ffffDD","#ff654d","#ffffff","#ffffff","#ffffff","#ffffff"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, android.R.id.text1, items);
menuList.setAdapter(adapter);