Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式更改视图的背景颜色_Android_Xamarin.android - Fatal编程技术网

Android 以编程方式更改视图的背景颜色

Android 以编程方式更改视图的背景颜色,android,xamarin.android,Android,Xamarin.android,我正试图使用我在参考资料中定义的颜色,以编程方式更改视图的背景颜色。其他SO帖子解释如下: int color = ContextCompat.GetColor(this.context, Resource.Color.my_color_background); this.myView.SetBackgroundColor(color); 但这对我不起作用,因为SetBackgroundColor采用的是颜色,而不是int。。。我做错了什么?我自己创建了颜色对象,并将其设置为: int col

我正试图使用我在参考资料中定义的颜色,以编程方式更改
视图的背景颜色。其他SO帖子解释如下:

int color = ContextCompat.GetColor(this.context, Resource.Color.my_color_background);
this.myView.SetBackgroundColor(color);

但这对我不起作用,因为
SetBackgroundColor
采用的是
颜色,而不是int。。。我做错了什么?

我自己创建了
颜色
对象,并将其设置为:

int color = ContextCompat.GetColor(context, Resource.Color.my_color);
this.view.SetBackgroundColor(new Color(color));

不确定为什么Xamarin中的构造函数不同…

是您使用的事件Android语法。我使用的是Xamarin,所以是C#,但我不认为这有什么区别?为什么需要
Color
而不是
int
?这就是我想知道的。。。