我意识到在这个问题上有很多话题,我已经看过他们。但我仍然很困惑,为什么我的ListView背景仍然是黑色的。只有当我将背景更改为构成我的ListView行的LinearLayout时,才能更改背景设置为某种颜色。但是,当我将LinearLayout的背景设置为某种颜色时,我无法查看选择器。我已经设置了cacheColorHint =“#00000000”,android:scrollingCache =“false”,甚至尝试了android:drawSelectorOnTop =“true”。我相信问题可能在于定义或创建我的选择器,因为我在测试应用程序时从未能够在屏幕上查看我的更改。但这都是猜测,因为我无法解决我的问题,我真的不知道什么是错的。您可以在下面查看我的代码。使用自定义选择器的ListView项目背景
我的选择:list_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:color="#80ff0000" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:color="#80ff0000" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:color="#80ff0000" /> <!-- pressed -->
<item android:color="#ffffffff" /> <!-- default -->
</selector>
我的ListView:main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff">
<!-- List view -->
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="0px"
android:divider="#0099CC"
android:listSelector="@drawable/list_background"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:scrollingCache="false"/>
</RelativeLayout>
我的LinearLayout:image_text_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<ImageView android:id="@+id/feed_image"
android:layout_width="100dip"
android:layout_height="100dip"
android:paddingTop="5dip"
android:paddingRight="3dip"
android:background="#00000000"/>
<TextView android:id="@+id/job_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF4444"
android:paddingTop="5dip"
android:paddingBottom="28dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:background="#00000000"/>
</LinearLayout>
我试过选项1,但似乎没有任何效果,除了我用ListView单击的能力被拿走了。然后我尝试了选项二,它看起来像我有一个充气器的问题,因为我的代码崩溃。我在堆栈跟踪中找到了这个。 '11-28 21:10:06.372:E/AndroidRuntime(29647):android.view.InflateException:二进制XML文件行#2:错误膨胀类android.widget.LinearLayout' – bmjohns