Skip to content

Instantly share code, notes, and snippets.

@gbaldera
Forked from nguyenhuy/Activity.java
Created May 17, 2014 18:34
Show Gist options
  • Save gbaldera/6e101fa398fcf32f2256 to your computer and use it in GitHub Desktop.
Save gbaldera/6e101fa398fcf32f2256 to your computer and use it in GitHub Desktop.
private BadgeView mBadgeView;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.badge_demo, menu);
MenuItem menuItem = menu.findItem(R.id.item_id);
ImageButton iconView = new ImageButton(this, null,
com.actionbarsherlock.R.style.Widget_Sherlock_ActionButton);
iconView.setImageDrawable(menuItem.getIcon());
iconView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// The thing is clicked, do something useful.
}
});
// The badge view requires target view (iconView in this case)
// to have a ViewGroup parent
LinearLayout container = new LinearLayout(this);
container.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
container.addView(iconView);
mBadgeView = new BadgeView(this, iconView);
mBadgeView.setText("10");
mBadgeView.show();
menuItem.setActionView(container);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment