android - 如何更改 Xamarin RemoteView 中的 TextBox 背景颜色
问题描述
我正在尝试在我的 Xamarin.Forms 应用程序中为 Android 创建一个小部件。我正在尝试练习的示例在这里:AppWidgetListView。问题是,我找不到改变 TextBox 背景颜色的方法。适用于 Java的remoteView.setInt(R.id.container, "SetBackgroundColor", backgroundColor);
方法在 Xamarin 中不起作用。此外,它甚至不会更改可绘制图片。拜托,你能帮帮我吗?
解决方案
您可以直接在布局中进行list_row.xml
,只需在根布局上设置背景
<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);
...
}
推荐阅读
- python - 点击Pygame时增加金钱
- android - Webview 在嵌套滚动视图中无法正常工作
- vim - 到字母,然后删除直到字母,然后重复
- python - 当前 URL 与其中任何一个都不匹配
- javascript - 如果您知道另一个键值,则从字典数组中获取键值
- svelte - 如何将原始文本作为命名插槽内容传递?
- python - 在 Jupyter Notebook 中使用当前文件夹之外的相对路径运行 Python 文件
- python - Scipy“不支持屏蔽数组”错误
- html - 我在哪里可以找到 WordPress 网站中使用的内联 CSS?
- python - 使用 IBApi 发送带有金额(美元)而不是数量的订单