使用自定义布局标记 xamarin.Android 的操作栏菜单项

Use a custom layout to badge xamarin.Android's action bar menu items

Check my action bar image here(My requirement)我想在 xamarin.android 动作蝙蝠(material 主题)上显示自定义文本标签按钮,请问有没有可能在 xamarin.android 中做到这一点建议...

static Button notifCount;
static int mNotifCount = 0;    

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main, menu);

    View count = menu.findItem(R.id.badge).getActionView();
    notifCount = (Button) count.findViewById(R.id.notif_count);
    notifCount.setText(String.valueOf(mNotifCount));
    return super.onCreateOptionsMenu(menu);
}

private void setNotifCount(int count){
    mNotifCount = count;
    invalidateOptionsMenu();
}


i tried above code converting into xamarin.android but it is showing like..

View count= menu.FindItem(Resource.Id.badge).getActionView ...Error...getActionview is not there in xamarin.

在 Xamarin 论坛上查看我关于此的 post。最近刚刚为推送通知做了这件事,但我不确定你的徽章是用于推送通知还是本地通知。我使用的是 Xamarin Forms,因此它可能与您略有不同,但如果您有任何问题,请告诉我。

基本上,在 OnCreateOptionsMenu 中你要确保你在你的特定页面上,然后将你的自定义徽章膨胀到操作栏中,然后添加自定义操作。

然后在 OnPrepareOptionsMenu 中您可以更新徽章计数。我使用数据库计算出新的徽章值应该是多少。

https://forums.xamarin.com/discussion/comment/183694/#Comment_183694

*编辑:我最近也发现了 this link,但没有深入研究。也可能有帮助。