Bug 35738 - ButtonRenderer UpdateTextColor function crash
Summary: ButtonRenderer UpdateTextColor function crash
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.1
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: E.Z. Hart [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-11-10 10:34 UTC by Dima
Modified: 2015-11-18 10:16 UTC (History)
4 users (show)

Tags: Android ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Dima 2015-11-10 10:34:11 UTC
Hello,

After updating Android support library for Xamarin.Forms, to 1.5.1, my app crashed.
After some research I figure out that app crashes when calling base.OnElementChanged in OnElementChanged function.
I started to view Xamarin disassembled library code and noticed that, if text color not default (in my case) Xamarin code get the color from ColorStateList wich is null in my case and that's why app crashed.

I would like to change the Button text color as I wish without getting mess with ColorStateList.

My workaround to avoid crash is:

protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
    if (Control == null) {//set custom control for the first time
        CustomNativeIconButton b = new CustomNativeIconButton(this);
        SetNativeControl(b);
    }
    //set Element color to default -> call base() -> change color
    var color = e.NewElement.TextColor.ToAndroid();
    e.NewElement.TextColor = Xamarin.Forms.Color.Default;
    base.OnElementChanged(e);
    Control.SetTextColor(color);
}

I hope you can return previous functionality so I don't have to change mine.
Thank you in advance.
Comment 1 Rui Marinho 2015-11-18 10:16:56 UTC
Should be fixed in 2.0.1-pre1