我正在开发一个板球应用程序.我的要求是这样的,如果我选择团队1必须显示可用国家名称的列表,如果我选择一个国家名称作为印度,则必须显示来自印度的玩家列表,并且我已经从中选择了多个玩家.我做了一切.但我的问题是我使用android.R.layout.simple_list_item_multiple_choice来选择玩家.我使用简单的列表视图,该列表的背景是黑色图像.我的列表视图就是这样
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8.5"
android:cacheColorHint="#00000000"
/>
Run Code Online (Sandbox Code Playgroud)
现在的问题是listview值显示为黑色.我已经有黑色背景图片.而且价值也是黑色的.所以看起来不太好.如何在不更改自定义适配器的情况下将listview值的颜色更改为白色.
这是我的适配器类
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,playersName);
lvview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lvview.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
您必须创建Custome TextView以更改所有颜色ListView items,而不是传递默认值android.R.layout.simple_list_item_multiple_choice,ArrayAdapter您应该传递自定义列表项XML,它具有不同的TextColor属性.
例如,在文件夹Layout下创建了custom_list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textColor="#FF00FF"
/>
Run Code Online (Sandbox Code Playgroud)
然后将其传递给适配器,如下所示:
new ArrayAdapter<String>(this, R.layout.custom_list_item, playersName);
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我测试过的工作正常的代码.
Run Code Online (Sandbox Code Playgroud)lv.setAdapter(new ArrayAdapter<String>(this, R.layout.custom_list_item, playersName)); lv.setBackgroundColor(Color.BLACK); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> p_arg0, View p_arg1, int p_arg2, long p_arg3) { my_sel_items = new String("Selected Items"); SparseBooleanArray a = lv.getCheckedItemPositions(); for (int i = 0; i < a.size(); i++) { if (a.valueAt(i)) { my_sel_items = my_sel_items + "," + (String) lv.getAdapter().getItem(i); } } Log.v("values", my_sel_items); } });
列表视图的布局
Run Code Online (Sandbox Code Playgroud)<ListView android:id="@+id/android:list" android:layout_marginTop="60dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#000000" />
样式.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
...other styles
Run Code Online (Sandbox Code Playgroud)
//添加这个
<style name="ListFont" parent="@android:style/Widget.ListView">
<item name="android:textColor">#FFFFFF</item>
</style>
...other styles
</resources>
Run Code Online (Sandbox Code Playgroud)
在布局 xml 中将此属性添加style="@style/ListFont"到 listview
| 归档时间: |
|
| 查看次数: |
14885 次 |
| 最近记录: |