1

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" />
11
  • 1
    Try changing this typeof(Android.Widget.Button) to the Xamarin Forms button, so typeof(Xamarin.Forms.Button) Commented Sep 16, 2016 at 7:28
  • Didn't work, the button has still the color from my style/theme :( Commented Sep 16, 2016 at 7:30
  • When you put a breakpoint in there, does it get hit at all? Commented Sep 16, 2016 at 7:42
  • Could have tried that earlier, sorry... But no, the breakpoint (at base.OnElementChanged(e);) doesn't get hitted :/ Commented Sep 16, 2016 at 7:44
  • Do I have to add more stuff in the Xamarin Portable project? I am adding the buttons via C#. Commented Sep 16, 2016 at 7:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.