Changing button color dynamically on Android

0

I have a menu, with 3 buttons, and I need to change their color dynamically in code.

I'm currently doing this:

mDrawable.setColorFilter (0xff0099cc, PorterDuff.Mode.SRC_IN);

What happens is that it correctly applies the color button, but when I change the activity and click on another button, the first button that is activated always has the color as if it was still activated. * This menu is included in the three activities.

In the image below it represents what happens, when I click on another button, it activates the other one but the first one remains with the color still.

    
asked by anonymous 08.03.2018 / 14:25

1 answer

0

You would need the code to see how you are doing, but basically, when you start an activity, the previous one is destroyed, that is, this tablayout would be destroyed and recreate a new one. Then you would have to for each activity, set in onCreate () the related colors, for example, if you are in the account screen, you would select the blue colors for that (icon and text of the account) (Remember that by default, all icons and texts will be white). So for each activity you would set the color of the page you are on.

Another way you could use to set the colors automatically would be to pass information from the previous activity to whatever you want ... this information would be just the color of the icon and you could pass it at the click.     

09.03.2018 / 17:26