1
我想将mvxbindable列表视图的高亮颜色从标准橙色自定义为动态颜色集。我认为这很容易,但我错了:)使用mvvmcross/mono droid自定义mvxbindablelist的选择器颜色
我发现我应该使用StateListDrawable在适配器中设置列表项的背景可绘制。我以下面的方式做到这一点(绿色是测试,_backgroundGradient是在构造函数中创建的);
public override View GetView(int position, View convertView, ViewGroup parent)
{
var view =base.GetView(position, convertView, parent);
StateListDrawable sld = new StateListDrawable();
sld.AddState(new int[] { Android.Resource.Attribute.StateFocused }, new ColorDrawable(Color.Green));
sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, new ColorDrawable(Color.Green));
sld.AddState(new int[] {}, _backgroundGradient);
view.Focusable = true;
if (view != null)
{
view.SetBackgroundDrawable(sld);
}
return view;
}
但是,当列表项被点击没有颜色我显示。下面是我的XML:
<listitem>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/dk.appsfabrikken.cmsapp"
android:id="@+id/tableViewItem"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:paddingBottom="1dp"
local:MvxBind="{'Click':{'Path':'ShowCellDetails'}}">
<CmsApp.Droid.Controls.UmbracoImageView
android:id="@+id/viewImagePreview"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="centerCrop"
android:padding="5dp"
local:MvxBind="{'ImageData':{'Path':'ImageIconData'},'HideImage':{'Path':'Hidden'}}" />
<TextView
android:layout_gravity="center_vertical"
android:id="@+id/title"
android:textStyle="bold"
android:textColor="@color/table_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
local:MvxBind="{'Text':{'Path':'Title'}}" />
</LinearLayout>
我必须失去了一些东西 - 任何帮助是高度赞赏。
你知道你可以直接在XML中做到这一点吗? – Cheesebaron
是的,但颜色的定义是动态的,并从web服务中反思。 – Bjarke