How to set icon color of MenuItem?

后端 未结 9 695
面向向阳花
面向向阳花 2021-01-30 12:37

I defined a menu item that has ShareActionProvider and share white icon like so :



        
9条回答
  •  孤城傲影
    2021-01-30 13:02

    try this :

    public boolean onCreateOptionsMenu(Menu menu) {
    
        getMenuInflater().inflate(R.menu.MENU, menu);
    
        // change color for icon 0 
        Drawable yourdrawable = menu.getItem(0).getIcon(); // change 0 with 1,2 ... 
        yourdrawable.mutate();
        yourdrawable.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_IN);
        return true;
    }       
    

提交回复
热议问题