Reputation: 892
I have the following class in my Droid-Project:
using MyProject.Droid;
using Xamarin.Forms.Platform.Android;
[assembly: Xamarin.Forms.ExportRenderer(typeof(Android.Widget.Button), typeof(ArrowButtonRenderer))]
namespace MyProject.Droid
{
public class ArrowButtonRenderer : Xamarin.Forms.Platform.Android.ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
var btn = this.Control as Android.Widget.Button;
btn.SetBackgroundColor(global::Android.Graphics.Color.Green);
}
}
}
I know, you dont need a custom renderer for changing a button's color, but I just wanna try things out :)
Cheers!
Edit: Here's the code about how I add the button's to the UI:
MyStackLayout.Children.Add(new Button
{
Text = "My Button Text"
});
And some buttons through xaml:
<Button x:Name="btnIdk" Text="something" />
Upvotes: 1
Views: 2645
Reputation: 33993
After an extensive chat and looking at your sources I've seen that the PCL has version 2.3.1.114 of Xamarin.Forms installed.
Your Droid project has version 1.5.x installed, so it's much older!
Now the next part will be tricky, you need to update your Xamarin.Forms package for Android. But if you update the Xamarin.Android.Support.* packages first, you'll get an error saying that your can't update Xamarin.Forms because no matching version of Forms is found.
Because Xamarin.Forms for Android depends heavily on the support packages they are linked to a specific version, but they're not always in sync. As of right now the Xamarin.Forms version (2.3.2.127) seems to miss the corresponding Android support packages. So don't upgrade to that, upgrade to the same version as your PCL which is 2.3.1.114. Then the Android packages will be updated to 23.3.0 and everything will work nicely.
Upvotes: 2