question

ozkaro-7807 avatar image
0 Votes"
ozkaro-7807 asked ozkaro-7807 edited

how to change values to the shape programatically on xamarin android?

I trying to implement shapes on my layout page but i have to place in "drawable" folder separately, and i can't call them implicitly, I have to call it within a "ImageView" as background but I need to change color's values for the shape
how can i do that?

thanks in advance!

dotnet-csharpdotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered ozkaro-7807 edited

Hello ozkaro,​

Welcome to our Microsoft Q&A platform!

To change the background color programatically, try to get the shape drawable and then use SetTint to change the color value.

Check the code:

//layout.xaml
<TextView
    android:id="@+id/text"
    android:background="@drawable/custom_shape"
    android:text="testing..."
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

//change the background
var text = FindViewById<TextView>(Resource.Id.text);
Drawable background = text.Background;
background.SetTint(Resource.Color.colorAccent);

Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I mean modify stroke width, color fill etc. but event works for what I want for
this line I have to change because the color what's shows dark

 background.SetTint(Resource.Color.colorAccent);

I change it for this one

 background.SetColorFilter(Android.Graphics,Color.Orange, PorterDuff.Mode.Multiply);

thanks @JarvanZhang-MSFT

1 Vote 1 ·

@ozkaro-7807
May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.

0 Votes 0 ·