johannilsson / android-actionbar

DEPRECATED Android Action Bar Implementation
1.31k stars 564 forks source link

How to change actionbar images dynamically #31

Closed molleman closed 13 years ago

molleman commented 13 years ago

Hello ,

I am currently using this actionbar in my application. One thing i cannot do though is changing a image of a button on the action bar.

So the button on the action bar controls a viewflipper below. when the view changes in the viewflipper i want to the button in the action bar to change also .

Is there any way of programitcally changing the action button dynamically?

johannilsson commented 13 years ago

Hi,

I would suggest you to try the new version that is in the branch mimic-native-api. Then you can simply use setIcon on the action.

d4tum commented 13 years ago

Hi Johan, I can't find a "setIcon" example anywhere in the mimic-native-api source. Would you please provide me with a one line example. Thank you for this great project.

JakeWharton commented 13 years ago

setIcon is part of the Action class, an instance of which represents each action item that appears on the action bar. There are two methods to set the icon on these instances. The associated source code is located here.

ActionBar.Action action = mActionBar.newAction()
                                    .setIcon(R.drawable.ic_star)
                                    .setOnMenuItemClickListener(/*...*/);
mActionBar.addAction(action);
d4tum commented 13 years ago

I'm a total GIT noob and I was cloning the android-actionbar master branch not the mimi-native-api code. I've down'ed a .zip of the mimic' repo and will see if I can make it work.

Thank you for your help.

johannilsson commented 13 years ago

Yes this is only available in that branch and of course in @JakeWharton's awesome Sherlock. Please let us know if you run into any problems.

duoduoluo commented 10 years ago

So, what's the solution if I use the original library?