这是我的列表视图的代码,如何更改listview的颜色
public class eat extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eat);
String [] Hotels ={"Deer Park","Araliya","Royal Lotus","Kandalama"};
ListAdapter hoteladapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Hotels);
ListView hotellist= (ListView)findViewById(R.id.lv);
hotellist.setAdapter(hoteladapter);
// hotellist.setc
}
答案 0 :(得分:1)
您可以指定列表项布局,如下所示
yourtextviewlayout.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:textColor="@color/your_color"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
并将此布局提供给ArrayAdapter
ListAdapter hoteladapter = new ArrayAdapter<String>(this,R.layout.yourtextviewlayout,Hotels);
答案 1 :(得分:0)
您必须实施自己的ListAdapter
,将数据项填充到自定义视图中。网上有很多教程。谷歌搜索将有所帮助。
答案 2 :(得分:0)
您需要以某种方式获取对包含文本的TextView对象的访问权。
您有几个选择:
快速而又肮脏:
ListAdapter hoteladapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Hotels) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView tv = (TextView) view.findViewById(android.R.id.text1);
tv.setTextColor(Color.RED);
return view;
}
};