how to reset the button background color in android?

mc 5,426 Reputation points
2025-02-14T04:42:24.1933333+00:00

in android. I create Button and set BackgroundTinitList then it can not reset background. how to reset it?

I have tried button.BackgroundTintList=null; button.Background =newButton.Background; it can not too;

Developer technologies .NET .NET MAUI
{count} votes

Accepted answer
  1. Anonymous
    2025-02-17T02:10:20.49+00:00

    Hello,

    You can save the button's previous BackgroundTinitList with property. Before you want to reset it. For example, you can save the BackgroundTinitList in the OnCreate method.

       ColorStateList OriginalColorStateList;
        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
     
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
     
            button1= FindViewById<Button>(Resource.Id.button1);
     
            OriginalColorStateList = button1.BackgroundTintList;
    ...
         }
    

    Then, you want to reset it. You can use button1.BackgroundTintList = OriginalColorStateList;.

    By the way, if you still cannot reset it, please share a mini demo with us.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.