【问题标题】:How to change the TextBox background color in Xamarin RemoteView如何更改 Xamarin RemoteView 中的 TextBox 背景颜色
【发布时间】:2021-08-19 17:22:17
【问题描述】:

我正在尝试在我的 Xamarin.Forms 应用中为 Android 创建一个小部件。我正在尝试练习的示例在这里:AppWidgetListView。问题是,我找不到改变 TextBox 背景颜色的方法。适用于 Java 的 remoteView.setInt(R.id.container, "SetBackgroundColor", backgroundColor); 在 Xamarin 中不起作用。此外,它甚至不会更改可绘制图片。 拜托,你能帮帮我吗?

【问题讨论】:

    标签: android xamarin widget


    【解决方案1】:

    你可以直接在布局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);
    
         ...
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-09
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 2017-10-03
      • 2011-11-11
      相关资源
      最近更新 更多