Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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
Xamarin(Android)中资源文件中按钮的SetBackgroundColor_Android_Button_Xamarin.android_Android Resources - Fatal编程技术网

Xamarin(Android)中资源文件中按钮的SetBackgroundColor

Xamarin(Android)中资源文件中按钮的SetBackgroundColor,android,button,xamarin.android,android-resources,Android,Button,Xamarin.android,Android Resources,我想设置按钮的背景色。我正在与Xamarin一起使用Visual Studio 在安卓系统中,我们使用: Java代码: button_vstrong_fluorescence.setBackgroundColor(ContextCompat.getColor(InventoryActivity.this, R.color.linear_filter_background)); 但在Xamarin C#代码 button_vstrong_fluorescence.SetBackgroundCo

我想设置
按钮的背景色。我正在与Xamarin一起使用Visual Studio

在安卓系统中,我们使用:

Java代码:

button_vstrong_fluorescence.setBackgroundColor(ContextCompat.getColor(InventoryActivity.this, R.color.linear_filter_background));
但在Xamarin C#代码

button_vstrong_fluorescence.SetBackgroundColor(Android.Graphics.Color.ParseColor("#EBECEC"));
C#中,上层代码可以正常工作

但每次我想纠正这件事

Android.Graphics.Color.ParseColor("#EBECEC")
有没有办法从我的资源中设置此颜色

Color.ParseColor
需要
String
值so

我尝试的是: 但它给了我下面的错误

有没有办法从资源中设置背景色

感谢您的帮助。

不是Xamarin(或C#)方面的专家,但类似的内容应该可以帮助您获得颜色资源:

button_vstrong_fluorescence
    .SetBackgroundColor(new Android.Graphics.Color(
        ContextCompat.GetColor(this, Resource.Color.linear_filter_background))
    );
试试看:

Android.Graphics.Color.ParseColor(Resource.Colors.linear_filter_background.ToString());

应该有效。

您好,您是否只是尝试将()放在ToString方法之后。是的,我尝试了,但它给了我错误。
Android.Graphics.Color.ParseColor(Resource.Colors.linear_filter_background.ToString());