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());