我在音乐播放器(而不是ListActivity)中有ListView,我试过我认为stackoverflow上的所有内容和点击项目后,行仍然没有另一种颜色。这是我的ListView代码:
<ListView
android:id="@+id/myMusicList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#242424"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selectorr"
android:paddingRight="20dp"
android:choiceMode="singleChoice"/>
这是我的列表选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@android:color/holo_red_light" />
<item
android:state_pressed="true"
android:drawable="@android:color/holo_blue_light" />
<item
android:state_selected="true"
android:state_pressed="false"
android:state_focused="false"
android:drawable="@android:color/holo_orange_light" />
</selector>
和行:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="5dp"
android:focusable="false">
<TextView
android:id="@+id/songTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
android:padding="10dp"
android:color="#f3f3f3"
android:focusable="false"/>
</LinearLayout>
这是代码:
ListView musicListView = (ListView) findViewById(R.id.myMusicList);
musicListView.setSelection(1);
musicListView.setItemsCanFocus(true);
...
ListAdapter adapter = new SimpleAdapter(this, songsListData, R.layout.playlist_item, new String[] { "songTitle" }, new int[] { R.id.songTitle });
musicListView.setAdapter(adapter);
musicListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
playSong(position);
view.setSelected(true);
}
});
我不知道出了什么问题 - 我尝试了“singleChoice”,用另一种颜色改变了选择器,编辑了可调焦的等等......
可能是什么问题?
答案 0 :(得分:0)
尝试更改您的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@android:color/holo_red_light"/>
<item android:state_activated="true" android:drawable="@android:color/holo_blue_light"/>
<item android:state_checked="true" android:drawable="@android:color/holo_blue_light"/>
<item android:drawable="@android:color/holo_red_light""/>
</selector>