如何更改 Xamarin RemoteView 中的文本框背景颜色
How to change the TextBox background color in Xamarin RemoteView
我正在尝试在我的 Xamarin.Forms 应用程序中为 Android 创建一个小部件。我尝试练习的例子在这里:AppWidgetListView。问题是,我找不到改变文本框背景颜色的方法。适用于 Java 的 remoteView.setInt(R.id.container, "SetBackgroundColor", backgroundColor);
在 Xamarin 中不起作用。此外,它甚至不会更改可绘制的图片。
拜托,你能帮帮我吗?
直接在layout中就可以了list_row.xml
,在root layout上设置背景即可
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@android:color/holo_green_dark" > //this line
如果您想在代码中更改它
//ListProvider.cs
public RemoteViews GetViewAt(int position)
{
RemoteViews remoteView = new RemoteViews( context.PackageName, Resource.Layout.list_row);
//add this line
remoteView.SetInt(Resource.Id.container, "setBackgroundColor", Android.Graphics.Color.Red);
...
}
我正在尝试在我的 Xamarin.Forms 应用程序中为 Android 创建一个小部件。我尝试练习的例子在这里:AppWidgetListView。问题是,我找不到改变文本框背景颜色的方法。适用于 Java 的 remoteView.setInt(R.id.container, "SetBackgroundColor", backgroundColor);
在 Xamarin 中不起作用。此外,它甚至不会更改可绘制的图片。
拜托,你能帮帮我吗?
直接在layout中就可以了list_row.xml
,在root layout上设置背景即可
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@android:color/holo_green_dark" > //this line
如果您想在代码中更改它
//ListProvider.cs
public RemoteViews GetViewAt(int position)
{
RemoteViews remoteView = new RemoteViews( context.PackageName, Resource.Layout.list_row);
//add this line
remoteView.SetInt(Resource.Id.container, "setBackgroundColor", Android.Graphics.Color.Red);
...
}