I've already got this working, except that the notifications don't update. In other words, it's a static notification right now, and I want to make it dynamic.
I followed this java code: http://stackoverflow.com/a/17972602
My code is below:
Custom item in menu - Main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/badge"
android:actionLayout="@layout/feed_update_count"
android:showAsAction="always"
android:title="Recent Alerts"
android:orderInCategory="9999" />
</menu>
Custom shape drawable - shape_notification.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<stroke
android:color="#22000000"
android:width="2dp"/>
<corners
android:radius="5dp" />
<solid
android:color="#ef4444"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<stroke
android:color="#22000000"
android:width="2dp"/>
<corners
android:radius="5dp" />
<solid
android:color="#CC0001"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Layout for my view - feed_update_notification.axml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingLeft="10dp">
<Button
android:id="@+id/notif_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="32dp"
android:minHeight="32dp"
android:background="@drawable/shape_notification"
android:textSize="16sp"
android:textColor="@android:color/white"
android:gravity="center"
android:padding="2dp"
android:singleLine="true">
</Button>
</RelativeLayout>
MainActivity - setting up (and attempting to update) my view
public static Button notifCount;
public static int mNotifCount = 0;
public override bool OnCreateOptionsMenu(IMenu menu) {
SupportMenuInflater.Inflate(Resource.Menu.Main, menu);
var count = menu.FindItem(Resource.Id.badge).ActionView;
notifCount = (Button)count.FindViewById<Button>(Resource.Id.notif_count);
notifCount.Text = mNotifCount.ToString();
return base.OnCreateOptionsMenu(menu);
}
public void setNotifCount(int count) {
mNotifCount = count;
SupportInvalidateOptionsMenu();
}