我想让我的ListView有三种背景颜色状态。ListView ContextMenu活动状态颜色
- 正常
- 按下(当用户的手指触摸)
- 上下文菜单中激活(在上下文菜单中出现的特定项目)
注:我没有当上下文菜单未激活时需要选择状态。
基本上,我很难过的部分是#3。当用户长按列表视图项目时,我想要显示上下文菜单,但我也希望他们按下的项目突出显示不同的颜色。
在代码中,我有这个
// note: the names are just to tell you what view type we're dealing with.
// android_Widgit_ListView: the ListView
// android_Views_View: the Cell
if (android_Widgit_ListView != null)
{
android_Views_View.Background = ContextCompat.GetDrawable(context, Resource.Drawable.listview_selector);
android_Widgit_ListView.SetSelector(Resource.Drawable.listview_selector);
android_Widgit_ListView.CacheColorHint = Color.Transparent.ToAndroid();
}
而且我有一个选择(注意不同的颜色只是为了看看这是怎么回事)
<!-- listview_selector.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@color/PrimaryMediumBlue"/>
<item android:state_activated="true" android:drawable="@color/PrimaryYellow"/>
<item android:state_selected="true" android:drawable="@color/SecondaryWarmGrey"/>
<item android:state_checked="true" android:drawable="@color/SecondaryGreen"/>
<item android:state_pressed="true" android:drawable="@color/SecondaryLightGrey"/>
<item android:drawable="@color/white"/>
</selector>
的问题是,当我长按该项目以调出上下文菜单,列表视图项目返回到白色。
如何获得该状态以保持不同的颜色?
我就沿着这条路走下去添加此。 Xamarin.Forms内部/密封所有的ContextMenu位:( –
达姆抱歉听到这一点。 – rrr