Issue
I want to set the background color of a Button
. I am using Visual Studio with Xamarin.
In Android we use:
Java code :
button_vstrong_fluorescence.setBackgroundColor(ContextCompat.getColor(InventoryActivity.this, R.color.linear_filter_background));
but In Xamarin C# code.
button_vstrong_fluorescence.SetBackgroundColor(Android.Graphics.Color.ParseColor("#EBECEC"));
In C# the upper code is work fine.
But every time i want right this thing static way
Android.Graphics.Color.ParseColor("#EBECEC")
Is there any way I can set #EBECEC
this color from my Resource.
the Color.ParseColor
require String
value so .
What I Try :
Android.Graphics.Color.ParseColor(Resource.Colors.linear_filter_background.ToString);
But it give me below error.
Is there any way to set Background color from Resource??
Any help be Apreciated.
Solution
Not an expert in Xamarin (or C#) but something like this should work to get your color resource:
button_vstrong_fluorescence
.SetBackgroundColor(new Android.Graphics.Color(
ContextCompat.GetColor(this, Resource.Color.linear_filter_background))
);
Answered By - earthw0rmjim
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.