如何在工具栏中更改菜单项的背景颜色? -Android-

时间:2019-01-29 15:37:49

标签: android

我正在使用Android。我的工具栏上有一个菜单项图标,当我单击它时,它会显示一个通知列表。 我想在显示列表时更改图标的背景色。就像eToro应用一样:

IMAGE: Icon hasn't been clicked and the background is the same as the toolbar

IMAGE: Icon has been clicked and the background color has changed

我该如何实现? 我的代码:

//Here, I inflate the options in the activity's menu
@Override
    public boolean onCreateOptionsMenu(Menu menu) { 
        getMenuInflater().inflate(R.menu.menu_management, menu);
        MenuItem menuItem = menu.findItem(R.id.notification_action);
        menuItem.setIcon(
            Converter.convertLayoutToImage(
                ManagementActivity.this,
                mNotificationCount,
                R.drawable.ic_notifications_white_24dp
            )
        );
        return  true;
    }



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.notification_action:
         //Here,on the item click event, I want to change the item's background color, as Etoro does.

         //...

         //Then I trigger the action.. 
         openNotificationListFragment();
    }
    return  true;
}

0 个答案:

没有答案