Tiutiu
Tiutiu

Reputation: 53

Android selector with icon

I'm trying to get the icon changing color when I press the icon like the toolbar on Instagram or like this Toolbar

I have searched and the only findings is the case of the button with text, I need with Icons.Thanks

Upvotes: 0

Views: 1053

Answers (1)

Tim Van Der Kuij
Tim Van Der Kuij

Reputation: 43

If you are using Vector Assets, then you can change the color in the xml with:

android:tint="@color/myColor" or android:tint="#ff00ff"

I recommend you use the colors.xml in the values folder. That way you can change the colors through the whole project at one place :)

Or in the code with:

iconName.setColorFilter(Color.parseColor("#ff00ff"));

If you want the color change to happen on a click, toggle or different event. Then you would just need to apply the corresponding listener. For example a OnClickListener if you want this to happen on a click.

nameOfClickableObject.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //to do code here
        }
    });

Edit: What are you currently using to display the icons? Have you got anything you could share?

Upvotes: 1

Related Questions