1.Layout for your badge menu item : actionbar_badge_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res
/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_gravity="right" >
<!-- Menu Item Image -->
<ImageView
android:layout_width="48dp"
android:layout_height="fill_parent"
android:clickable="true"
android:src="@drawable/Notificationicon" />
<!-- Badge Count -->
<TextView
android:id="@+id/actionbar_notifcation_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/badge_circle"
/>
2.main.xml file :
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/badge"
android:actionLayout="@layout/actionbar_badge_layout"
android:title="Notification"
android:showAsAction="always">
</item>
</menu>
3.Within MainActivity :
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.badge, menu);
RelativeLayout badgeLayout = (RelativeLayout)
menu.findItem(R.id.badge).getActionView();
TextView tv = (TextView)
badgeLayout.findViewById(R.id.actionbar_notifcation_textview);
tv.setText("10");
}
4.Emulator OutPut :
TextView(badge) is not setting to 10, in Emulator blank textview is showing.
5.Now iam using ActionBar with sliding menu.