Menu in Action bar Android

后端 未结 2 649
梦谈多话
梦谈多话 2021-01-16 15:54

I have created ActionBar with some number of tabs dynamically like the below code.

public void addTabBar(Context context)
{       
    sActiveContext=context         


        
2条回答
  •  有刺的猬
    2021-01-16 16:16

    Try this, In your Activity,

    private Menu menu=null;
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
       this.menu=menu;
       //  call here as, showMenu(R.drawable.menu_image,2222);
       return true;
    }
    private void showMenu(int imageIcon,int id)//Where imageIcon is R.drawable.menu_image
    {
       menu.add(0, id, 0, actionString).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);;
       MenuItem item=menu.findItem(id);
       item.setIcon(imageIcon);
    }
    

提交回复
热议问题