在动作条动态更改图标 [英] Change icons in ActionBar dynamically

查看:120
本文介绍了在动作条动态更改图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其中有一个动作条的活动,但我需要动态地更改了动作条的图标,我有一个暂停和播放按钮,我需要的暂停按钮就可以了用户点击更换播放按钮。我已搜查,我发现它:

I have an Activity which has an ActionBar but I need to change the icons on the ActionBar dynamically, I have a pause and a play button and I need to replace the play button with the pause button as the user click on it. I have searched and I found it:

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if(DEBUG) Log.i("onCreateOptionsMenu()", "onCreateOptionsMenu() -> LogicAnalizerView");

        //menu.add("").setIcon(R.drawable.pause).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.actionbarlogic, menu);
        menu.removeItem(R.id.pauseLogic);

        return true;
    }

因此​​,在这种方式,我删除了暂停按钮,我可以将其添加太多,但是当我开始了活动和动作条绘制它才会发生。我怎么可以强制重绘动作条?此外,在这条路上,整个动作条被重绘是这样吗?什么办法可以只重绘按钮/图标,我想要什么?

So in this way I remove the Pause button and I can add it too, but it only happen when I start the Activity and the ActionBar is drawn. How can I force to redraw the ActionBar? Also, on this way the whole ActionBar is redrawn is that right? Is any way to redraw only the button/icon i want?

感谢您:)

推荐答案

我解决了在这里描述:<一href="http://developer.android.com/guide/topics/ui/menus.html">http://developer.android.com/guide/topics/ui/menus.html

这篇关于在动作条动态更改图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆