Change icons in ActionBar dynamically

后端 未结 6 1979
滥情空心
滥情空心 2020-12-04 10:58

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 <

6条回答
  •  忘掉有多难
    2020-12-04 12:03

    If you want to get the first item from your menu, **

    use menu.getItem(0);

    this Code woks perfectly :

     @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.my_menu, menu);
           MenuItem m =  menu.getItem(0);
           m.setIcon(R.drawable.your_icon_here);
        }
    
    
        return true;
    }
    

提交回复
热议问题