点击ListView时背景阴影

只需要在ListView的item里面父控件添加一个选择器

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_item_selector"
     >
***********************************************************
</RelativeLayout>



<item android:drawable="@color/item_bg" android:state_pressed="true"/>      <color name="item_bg">#dfdfdf</color> <!-- 条目背景 -->
<item android:drawable="@color/white"/>                                      <color name="white">#FFFFFF</color>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF中的ListView控件可以通过设置ItemContainerStyle来自定义行的背景颜色。 首先,我们需要在XAML中定义ListView控件,并将其绑定到数据源。然后,可以使用ListView的ItemContainerStyle属性设置行的样式。 要设置行的背景颜色,可以使用XAML中的触发器(Trigger)来实现。我们可以为ListView的ItemContainerStyle属性添加一个样式(Style),并在该样式内使用触发器来根据条件设置行的背景颜色。 以下是一个示例代码: ```xml <ListView ItemsSource="{Binding YourDataSource}"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="LightGray"/> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="White"/> </Trigger> </Style.Triggers> </Style> </ListView.ItemContainerStyle> </ListView> ``` 在上述代码中,我们使用了AlternationIndex属性来为交替的行设置不同的背景颜色。AlternationIndex属性将自动递增并应用于ListView的每一行。通过将AlternationIndex的值与触发器中的值匹配,我们可以为奇数行和偶数行分别设置不同的背景颜色。 在示例中,我们为奇数行设置了浅灰色(LightGray)的背景颜色,偶数行设置了白色(White)的背景颜色。你可以根据需要自定义触发器的条件和背景颜色。 通过这种方式,我们可以自定义ListView行的背景颜色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值