1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Material ComponentでToolbarのmenuにBadgeを表示させる

Posted at

material-components 1.3.0 から Toolbar の menu に Badge を簡単に表示できるようになりました。

実装

val badge = BadgeDrawable.create(requireContext())
BadgeUtils.attachBadgeDrawable(badge, toolbar, R.id.action_info)

material-components にある BadgeUtils を使います。
(BadgeUtils は Experimental なので今後変更される可能性があります)
attachBadgeDrawable で Toolbar と表示させたい menu の id を渡すことで Badge を表示させることができます。

これまで頑張っていた Badge の表示がとても簡単になって最高ですね。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?