Android的ListView的风格风格、Android、ListView

2023-09-06 04:44:40 作者:从今往后,做个明白人,分得出友情,拎得清爱情。小编为大家送上

我有一个列表视图的问题。我希望有人知道的解决方案,因为我一直在试图解决这个问题,所有的周末。

I have a question about list views. I hope someone knows the solution, because I have been trying to solve this problem all weekend.

我有一个自定义列表视图中的每一行有个规矩的.xml ( item_row.xml )与一组彩色背景的行项目。

I have a custom list view in which every row have a custom .xml (item_row.xml) with a set color background for the row item.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="70dip"
  android:orientation="vertical"
  android:background="@drawable/list_bg">

现在的问题是,当我尝试做一个选择的名单。我想两件事情:

The problem is that when I try to make a selector for the list. I want two things:

当该项目的重点是,典型的橙色矩形应该出现了吧, 和相同的。当产品pressed。

我已经证明了选择和自定义风格,但我得到的是,或选择不显示或选择覆盖的项目,所以我无法看到它。

I have proved with a selector and a custom style but all I get is or the selector doesn't appear or the selector covering the item so I can't see it.

如果有人可以帮助我找到正确的code我将非常感激。

If anyone could help me with finding the right code I would be very grateful.

感谢

推荐答案

属性添加到您的的ListView 标记。

android:listSelector="@drawable/list_bg"

现在,你可以创建自己的风格,使用XML文件作为绘制你的背景。欲了解更多信息,请查看API演示应用程序,可绘制部分。

Now you can create your own style for your background using the XML file as drawable. For more information, check out the API Demos app, drawables section.