如何在Android的ListView中选定的项目我的风格? [英] How do I style selected item in Android ListView?
问题描述
我是一个Android新手试图了解事情的UI端和它做我的头在这里就是我现在所拥有的:
I am an Android newbie trying to learn the UI side of things and it's doing my head in. Here's what I have right now:
breeds_listing.xml
breeds_listing.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ListView android:id="@+id/breedsListView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:dividerHeight="0px" android:divider="#00000000"></ListView>
</LinearLayout>
breeds_listing_item.xml
breeds_listing_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/list_item_background"
android:orientation="horizontal" >
<TextView android:id="@+id/allbreeds_single_item"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center_horizontal"></TextView>
</LinearLayout>
list_item_background.xml
list_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#043402" />
<stroke android:width="3dp" color="#ffff8080" />
<corners android:radius="8dp" />
<padding android:left="10dp" android:top="10dp" android:right="10dp"
android:bottom="10dp" />
</shape>
我很努力弄清楚是怎么做的我样式选定的项目?目前选定的项目都有一个可怕的橙色背景当中,圆角绿色矩形下,给出了一个橙色的轮廓效果。我敢肯定,我没有做过的事情符合最佳做法,使任何建议或改进将大大AP preciated。
What I am struggling to figure out is how do I style the selected item? At the moment the selected item has a ghastly orange background which, under the rounded green rectangle, gives an orange outline effect. I'm sure I have not done things in line with best practices so any suggestions or improvements would be greatly appreciated.
非常感谢, ð。
推荐答案
我这样做:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape >
<solid android:color="#929292" />
</shape>
</item>
<item>
<shape >
<solid android:color="#FFFFFF" />
</shape>
</item>
</selector>
所以,你可以使用这个属性安卓STATE_ pressed =真正的
在我的例子中,单元格的背景只会是白色和灰色当pressed。
In my example, the cell background will only be white, and grey when pressed.
我希望它能帮助!
这篇关于如何在Android的ListView中选定的项目我的风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!