Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

[Android] Color.Default based on Context

$
0
0

So in my custom renderer, I have a piece of code that is to update the TextColor of an EditText.

private void SetTextColor()
{
    if (Element.TextColor == Color.Default)
    {
        var e = new EditText(Context);
        NativeView.EditText.SetTextColor(e.TextColors);
    }
    else
    {
        NativeView.EditText.SetTextColor(Element.TextColor.ToAndroid());
    }
}

As you can see, if the default color is set to Default, I new up an EditText based on the Context and then use it's TextColors property. This is working just fine, however I'd like to know how to make the Color.Default property Context aware. In other words, it needs to know the theme and set itself accordingly.

If I were to use the following snippet along with a light theme, the TextColor would disappear since "Color.Default" is white.

private void SetTextColor()
{
    if (Element.TextColor == Color.Default)
    {
        NativeView.EditText.SetTextColor(Color.Default.ToAndroid());
    }
    else
    {
        NativeView.EditText.SetTextColor(Element.TextColor.ToAndroid());
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>