-
-
Save gbaldera/6e101fa398fcf32f2256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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