Android 如何更改listview中行的背景色

Android 如何更改listview中行的背景色,android,listview,backcolor,Android,Listview,Backcolor,你好,我正在开发购物应用程序 这是我的代码,我想更改listview中行的背景色 当项目数量大于0时,以便我可以将 顾客购买的物品和非顾客购买的物品 我使用这个xml来显示我的项目列表 我提前通知你 自定义列表的最佳方法是使用其中一条注释中提到的适配器。 如果您不清楚如何使用它们,请参阅上面的添加颜色属性您的ListView还可以添加适配器代码。好的,我试试,谢谢 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xm

你好,我正在开发购物应用程序

  • 这是我的代码,我想更改listview中行的背景色 当项目数量大于0时,以便我可以将 顾客购买的物品和非顾客购买的物品

  • 我使用这个xml来显示我的项目列表

    我提前通知你



  • 自定义列表的最佳方法是使用其中一条注释中提到的适配器。
    如果您不清楚如何使用它们,请参阅上面的添加颜色属性您的ListView还可以添加适配器代码。好的,我试试,谢谢
    <?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:background="#AED581"
    android:orientation="vertical"
    android:weightSum="100" >
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="40"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Items" />   
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <EditText
    android:id="@+id/et_searchbar"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:ems="10"
    android:singleLine="true" >
    </EditText>
    <Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/et_searchbar" />
    <Button
    android:id="@+id/bt_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/et_searchbar"
    android:text="Search"
    android:textSize="10dp" />
    </RelativeLayout>
    </LinearLayout>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="15"
        android:orientation="vertical" >
    <ListView
            android:id="@+id/expandableListView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    </ListView>
    </LinearLayout>    
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="45"
    android:orientation="horizontal" >
    <TextView
    android:id="@+id/tv_Total"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btn_checkout"
    android:layout_alignBottom="@+id/btn_checkout"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/textView2"
    android:text="0" />
    
    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="20dp"
    android:paddingLeft="5dp"
    android:text="Total    Rs:" />
    
    <Button
    android:id="@+id/btn_checkout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginRight="26dp"
    android:background="@drawable/buttonstyle"
    android:text="Checkout" />
    </RelativeLayout>
    </LinearLayout>