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

时间:2016-03-22 11:29:36

标签: xamarin xamarin.android

Check my action bar image here(My requirement)我想在xamarin.android动作蝙蝠(材料主题)上显示自定义文本标签按钮,有没有可能在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.

1 个答案:

答案 0 :(得分:0)

在Xamarin论坛上查看我的帖子。最近刚刚为Push Notifications做了这个,但我不确定你的徽章是用于推送还是本地通知。我正在使用Xamarin Forms,所以它可能与您有点不同,但如果您有任何问题,请告诉我。

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

然后在OnPrepareOptionsMenu中,您可以更新徽章计数。我使用数据库来确定新徽章值应该是什么。

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

*编辑:我最近也找到了this link,但没有仔细研究过。可能也会有所帮助。