我正在尝试更改 ListView 中的颜色,因为我想使用白色背景。不触摸 ListView 它不显示任何文本。触摸时背景切换为黑色,并且文本可见,因为文本是白色的。如何更改 Textcolour 并避免触摸时背景改变其颜色?这是我的代码:
public class LayoutNight extends Fragment {
ListView myList;
String[] listContent = {
"Mo",
"Di",
"Mi",
"Do",
"Fr",
"Sa",
"So"
};
public static Fragment newInstance(Context context) {
LayoutNight f = new LayoutNight();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_night, null);
myList = (ListView)root.findViewById(R.id.list);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_multiple_choice,
listContent);
myList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
myList.setAdapter(adapter);
// That was a try, but it crashed ...
// TextView myListText = (TextView)root.findViewById(R.id.list);
// myListText.setTextColor(color.black);
return root;
}
}
编辑
我做了Raghunandan的建议,但背景没有改变。这是原封不动的截图
这是滚动时的屏幕(不幸的是黑色)
这是选择选项的屏幕
编辑 它现在就像在滚动时不改变背景一样工作(感谢Pragnani和Raghunandan),但它不可点击的。我怎样才能让它可点击?
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/listbkg"
android:drawSelectorOnTop="true"
android:cacheColorHint="@android:color/transparent">
</ListView>
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5px"
android:paddingBottom="5px"
android:textSize="35sp"
android:textColor="#000000"
android:layout_gravity="center"
android:maxHeight="75px"/>
代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_night, null);
myList = (ListView)root.findViewById(R.id.list);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(getActivity(),R.layout.list_row,listContent);
myList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
myList.setFocusable(true);
myList.setClickable(true);
myList.setAdapter(adapter);
return root;
}