user3898113
user3898113

Reputation: 35

How to add click event on Android Action Bar

I have added one star icon on Action Bar. Now I want to add click event on that star. If the star is clicked then it should be bright or Turned ON which is OFF by default. And if that star is ON and clicked, then it should go to OFF. I am not getting any idea how to perform onClick event on action bar.

Upvotes: 1

Views: 4220

Answers (2)

REG1
REG1

Reputation: 486

To add onClickListener to a view in your action bar you have to create a reference to that view first and then in the onCreateOptionsMenu() method you can register the onClickListener. See the answer to this question here. Its the same principle, you're simply using a 'star icon' instead of a switch.

Upvotes: 0

codebot
codebot

Reputation: 2646

You have a good example here.

Action Bar Example

Upvotes: 3

Related Questions