Android的列表视图不再突出选择的onclick [英] Android listview no longer highlights selection onclick
问题描述
我有一个是显示,当我接触了他们对项yellowtint列表视图。所有我所做的不同是改变背景图像中的列表视图XML,现在它不再会告诉我yellowtint
I have a listview that was showing a yellowtint on items when I touched them. All I've done differently is change the background image in that listview xml , and now it no longer will show me the yellowtint
下面是code
列表视图中的XML,它仅仅是一个与背景图像TextView的:
the list view xml, it is just a textview with a background image:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="24sp"
android:textColor="#000000"
android:background="@drawable/bglistitem"
android:gravity="center_vertical|center_horizontal">
</TextView>
在那里它被称为在另一个布局的地方
the place in another layout where it is called
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="24sp"
android:textColor="#000000"
android:background="@drawable/bglistitem"
android:gravity="center_vertical|center_horizontal">
</TextView>
和这里是code:
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {}
});
,你可以在上面看到的,我从来没有做任何事情,会改变选择高亮的默认行为,为什么会这样,现在是不同的,你看,我不认为或许是?
as you can see above, I was never doing anything that would change the default behavior of the selection highlighting, why would this be different now, perhaps something you see that I don't see?
推荐答案
当你添加了一个新的背景到ListView你推翻机器人这是最有可能使用一个选择器着色取决于他们的状态ListItems的默认背景。
When you added a new background to the ListView you overrode androids default background that was most likely using a selector to tint the ListItems depending on their state.
尝试使用自定义选择
创建一个XML文件,mycustombackground.xml,并且将其添加到它:
Create an XML file, mycustombackground.xml, and add this to it:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/item_focused" />
<item android:drawable="@drawable/item_normal" />
</selector>
替换为自己的@drawables相对于状态。 那么你的列表视图的背景设定在XML文件中。
Replace the @drawables with your own in relation to the state. Then set the background of your listview to the xml file.
android:background="@drawable/mycustombackground"
您可能想看看到XML创建黄色,或者只是创建自己的形象。
You may want to take a look into the XML to create the yellow color, or just create your own image.
这篇关于Android的列表视图不再突出选择的onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!