Changing the color of a single color drawable png

Nathan Sokalski 4,126 Reputation points
2024-09-22T19:48:38.7466667+00:00

I have a Xamarin.Android project with several single color (black & transparent) png's in my Drawable folder. I want to be able to dynamically make these images different colors by specifying a System.Drawing.Color or Android.Graphics.Color. To put is simply, I need to fill the black area of the png with a dynamically specified color. Is there a way to do this? Thanks.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,346 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,823 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,887 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 75,036 Reputation points Microsoft Vendor
    2024-09-23T02:00:17.4533333+00:00

    Xamarin support ended on May 1, 2024 for all Xamarin SDKs including Xamarin.Forms. For more information, please check: Xamarin official support policy | .NET (microsoft.com). We will recommend you upgrade Xamarin projects to . NET MAUI, please see the Upgrade from Xamarin to .NET & .NET MAUI documentation.

    To put is simply, I need to fill the black area of the png with a dynamically specified color. Is there a way to do this?

    You can use imageView.SetBackgroundColor(Android.Graphics.Color.Green);,

    I test with transparent png file in the ImageView and set it with above code, it is working.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.