{"id":20892687,"url":"https://github.com/aweiloveandroid/abadgeview","last_synced_at":"2025-10-13T07:09:55.423Z","repository":{"id":185905699,"uuid":"674264829","full_name":"AweiLoveAndroid/ABadgeView","owner":"AweiLoveAndroid","description":"help to add badge icon in android.","archived":false,"fork":false,"pushed_at":"2023-08-05T02:21:08.000Z","size":517,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T19:12:42.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AweiLoveAndroid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-03T14:15:15.000Z","updated_at":"2024-05-07T11:15:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"5ed4c50d-d1ae-4100-822a-14efd3b76f36","html_url":"https://github.com/AweiLoveAndroid/ABadgeView","commit_stats":null,"previous_names":["aweiloveandroid/abadgeview"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AweiLoveAndroid/ABadgeView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AweiLoveAndroid%2FABadgeView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AweiLoveAndroid%2FABadgeView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AweiLoveAndroid%2FABadgeView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AweiLoveAndroid%2FABadgeView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AweiLoveAndroid","download_url":"https://codeload.github.com/AweiLoveAndroid/ABadgeView/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AweiLoveAndroid%2FABadgeView/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014105,"owners_count":26085461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T10:13:36.839Z","updated_at":"2025-10-13T07:09:55.401Z","avatar_url":"https://github.com/AweiLoveAndroid.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"ABadgeView\n============\n\nAndroid Badge for any View.\nAlso you can add badge in Menu, for example: `Toolbar`, `BottomNavigationView`, `TabLayout`,`DrawerLayout`,etc...\n\n### Gradle Init\n\n* 1.in your project root `build.gradle` add maven repositories, like this:\n\n```groovy\nmaven { url 'https://jitpack.io' }\n``` \n\n* 2.in your module `build.gradle` add dependencies, like this:\n\n```groovy\ndependencies {\n    implementation 'com.lzw.badgeview:lib:0.1.0'\n    annotationProcessor 'com.lzw.badgeview:compiler:0.1.0'\n}\n```\n\nIf the libs that you  implementation contains `com.google.android.material`, you should exclude it.like this:\n\n```groovy\nimplementation ('androidx.navigation:navigation-ui:2.3.5') {\n    exclude group: 'com.google.android.material', module: 'material'\n}\n```\n\n\n### Init ABadgeView\n\nUse the bytecode of those classes that require add badges functionality as a parameter in the ABadge annotation. (The following code block provides an example, and the corresponding lines can be deleted if not needed.)\n\n```Java\n@ABadge({\n    View.class, // equeals: com.lzw.badgeview.ABadgeView, if you don't use it, just delete this line.\n    ImageView.class, // equeals: com.lzw.badgeview.ABadgeImageVieww, if you don't use it, just delete this line.\n    TextView.class, // equeals: com.lzw.badgeview.ABadgeFloatingTextView, if you don't use it, just delete this line.\n    RadioButton.class, // equeals: com.lzw.badgeview.ABadgeRadioButton, if you don't use it, just delete this line.\n    LinearLayout.class, // equeals: com.lzw.badgeview.ABadgeLinearLayout, if you don't use it, just delete this line.\n    FrameLayout.class, // equeals: com.lzw.badgeview.ABadgeFrameLayout, if you don't use it, just delete this line.\n    RelativeLayout.class, // equeals: com.lzw.badgeview.ABadgeRelativeLayout, if you don't use it, just delete this line.\n    FloatingActionButton.class, // equeals: com.lzw.badgeview.ABadgeFloatingActionButton, if you don't use it, just delete this line.\n    ...\n})\npublic class ABadgeInit {\n}\n```\n3. In Android Studio , click [Build] =\u003e [Rebuild Project]\n\n4. Now you can use 「com.lzw.badgeview.ABadgeXXX」in your project.\n\n### Api Method\n\n* void showCirclePointBadge();\n\n* void showTextBadge(String badgeText);\n\n* void hiddenBadge();\n\n* void showDrawableBadge(Bitmap bitmap);\n\n* void setDragDismissDelegage(BGADragDismissDelegate delegate);\n\n* boolean isShowBadge();\n\n* boolean isDraggable();\n\n* boolean isDragging();\n\n### Badge Attrs\n\nAttrs Name | Description | Default value\n:----------- | :----------- | :-----------\nbadge_bgColor         | Badge background color.        | Color.RED\nbadge_textColor         | Badge text color.         | Color.WHITE\nbadge_textSize         | Badge text text size.        | 10sp\nbadge_verticalMargin         | The vertical margin between the badge background and anchorView.        | 4dp\nbadge_horizontalMargin         | The horizontal margin between the badge background and anchorView.        | 4dp\nbadge_padding         | The padding between tadge text edge and  the badge background edge.       | 4dp\nbadge_gravity         | Badge alignment in anchor view.        | BGABadgeImageView和BGABadgeRadioButton是右上方，其他控件是右边垂直居中\nbadge_draggable         | Do you want to enable drag and drop to delete Badge?        | false\nbadge_isResumeTravel         | Do you want to restore the trajectory when dragging the Badge beyond the trajectory range and placing it back into the trajectory range again?        | false\nbadge_borderWidth         | Badge border width        | 0dp\nbadge_borderColor         | Badge border color         | Color.WHITE\nbadge_dragExtra         | Trigger the extended touch distance to start dragging Badge event.       | 4dp\n\n\n\n### Use badge in `BottomNavigationView`\n\nThree ways:\n\n\u003e 1.Use BadgeDrawable\n\n```java\n// 使用官方的BadgeDrawable：\nBadgeDrawable badgeDrawable = bottomNavigationView.addBadgeCustom(R.id.navigation_home);\nbadgeDrawable.setBadgeGravity(BadgeDrawable.TOP_END);\nbadgeDrawable.setNumber(100);\n```\n\n\u003e 2.Use Xml layout\n\n```java\n// 使用xml布局加载\nbottomNavigationView.addBadgeFromXmlLayout(BottomNavActivity.this, 1, R.layout.layout_custom_badge_xml);\n```\n\n\u003e 3.Use ABadgeView\n\n```java\n// 使用自定义ABadgeView\nbottomNavigationView.setIsNeedShowBadge(true);\nbottomNavigationView.bindTargetItemIndex(2)\n//  .setBadgeText(\"10\")//设置显示数字\n    .setBadgeNumber(10)//设置显示数字\n    .setBadgeGravity(Gravity.END | Gravity.TOP)//设置显示位置\n    .setBadgeTextSize(8, true)//设置字体大小，后边的true是指使用sp为单位\n    .setBadgeGravityOffset(5, 0, true)\n    .setBadgePadding(8, true)\n    .setBadgeBackgroundDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.shape_bg_red, null))//设置自定义背景，红色填充，绿色边框\n    .setBadgeIsDraggable(true)\n    .setOnBadgeDragStateChangedListener(new OnBadgeDragStateChangedListener() {\n        @Override\n        public void onBadgeDragStateChanged(int dragState, String stateTag, IABadge badge, View targetView) {\n            Log.d(TAG, \"onBadgeDragStateChanged: dragState=\" + dragState + \", stateTag=\" + stateTag);\n            if (dragState == ABadgeDragState.STATE_SUCCEED) {\n                bottomNavigationView.setIsNeedShowBadge(false);\n            }\n        }\n    });\n```\n\n### Use badge in `TabLayout`\n\nSample code:\n\n```java\n    //set the badge\n    BadgeDrawable badgeDrawable = tabLayout.getTabAt(0).getOrCreateBadge();\n    badgeDrawable.setVisible(true);\n    badgeDrawable.setBadgeText(\"5\");\n\n    BadgeDrawable badgeDrawable2 = tabLayout.getTabAt(1).getOrCreateBadge();\n    badgeDrawable2.setVisible(true);\n    badgeDrawable2.setBadgeText(\"20\");\n\n    BadgeDrawable badgeDrawable3 = tabLayout.getTabAt(2).getOrCreateBadge();\n    badgeDrawable3.setVisible(true);\n    badgeDrawable3.setBadgeText(\"测试\");\n\n//  you can use setCustomView ,add your custom badge view in TabLayout items.\n//        tabLayout.getTabAt(0).setCustomView(R.layout.layout_custom_tab_xml);\n//        tabLayout.getTabAt(1).setCustomView(R.layout.layout_custom_tab_xml);\n//        tabLayout.getTabAt(2).setCustomView(R.layout.layout_custom_tab_xml);\n```\n\n### Use badge in `Toolbar`\n\nMore information see: [ABadgeMenuItemHelper.java](lib/src/main/java/com/lzw/badgeview/menu/ABadgeMenuItemHelper.java)\n\nSample code:\n\n```java\n @Override\n    public boolean onCreateOptionsMenu(Menu menu) {\n        // Inflate the menu; this adds items to the action bar if it is present.\n        getMenuInflater().inflate(R.menu.toolbar_menu, menu);\n\n        //you can add some logic\n        MenuItem menuItem1 = menu.findItem(R.id.toolbar_menu_item1);\n        MenuItem menuItem2 = menu.findItem(R.id.toolbar_menu_item2);\n        MenuItem menuItem3 = menu.findItem(R.id.toolbar_menu_item3);\n\n        Drawable menuItemDrawable1 = menuItem1.getIcon();\n        Drawable menuItemDrawable2 = menuItem2.getIcon();\n        Drawable menuItemDrawable3 = menuItem3.getIcon();\n\n        // 隐藏当前MenuItem\n//        new ABadgeMenuItemHelper(ToolbarBadgeActivity.this).hideMenuItem(menuItemHome);\n\n        // 如果传入负数，或者0 则不会badge\n        new ABadgeMenuItemHelper(ToolbarBadgeActivity.this).show(\n                menuItem1,\n                getResources().getDrawable(R.mipmap.tab_discover_normal),\n                getResources().getDrawable(R.mipmap.tab_discover_checked),\n                0,\n                ABadgeStyleDefault.RED_ROUND,\n                null);\n\n        new ABadgeMenuItemHelper(ToolbarBadgeActivity.this).show(\n                menuItem2,\n                getResources().getDrawable(R.mipmap.tab_me_normal),\n                getResources().getDrawable(R.mipmap.tab_me_checked),\n                100,\n                ABadgeStyleDefault.RED_ROUND_RECT,\n                new ABadgeMenuItemClickListener() {\n                    @Override\n                    public void onOptionsItemSelected(MenuItem menuItem) {\n                        if (menuItem.getItemId() == R.id.toolbar_menu_item2) {\n                            Toast.makeText(ToolbarBadgeActivity.this, \"自定义监听 ==\u003e 点击了按钮2\", Toast.LENGTH_SHORT).show();\n                        }\n                    }\n                });\n\n        new ABadgeMenuItemHelper(ToolbarBadgeActivity.this).show(\n                menuItem3,\n                menuItemDrawable3,\n                \"测试\",\n                ABadgeStyleDefault.RED_ROUND_RECT,\n                new ABadgeMenuItemClickListener() {\n                    @Override\n                    public void onOptionsItemSelected(MenuItem menuItem) {\n                        if (menuItem.getItemId() == R.id.toolbar_menu_item3) {\n                            Toast.makeText(ToolbarBadgeActivity.this, \"自定义监听 ==\u003e 点击了按钮3\", Toast.LENGTH_SHORT).show();\n                        }\n                    }\n                });\n\n        return true;\n\n\n    }\n```\n\n### Use badge in `DrawerLayout`\n\nSample code:\n\n```java\n    MenuItem menuItem1 = navigationView.getMenu().getItem(0);\n    MenuItem menuItem2 = navigationView.getMenu().getItem(1);\n    MenuItem menuItem3 = navigationView.getMenu().getItem(2);\n\n    Drawable menuItemDrawable1 = menuItem1.getIcon();\n    Drawable menuItemDrawable2 = menuItem2.getIcon();\n    Drawable menuItemDrawable3 = menuItem3.getIcon();\n\n    // 隐藏当前MenuItem\n//        new ABadgeMenuItemHelper(DrawerActivity.this).hideMenuItem(menuItemHome);\n\n    // 如果传入负数，或者0 则不会badge\n    new ABadgeMenuItemHelper(DrawerActivity.this).show(\n        menuItem1,\n        getResources().getDrawable(R.mipmap.tab_discover_normal),\n        getResources().getDrawable(R.mipmap.tab_discover_checked),\n        0,\n        ABadgeStyleDefault.RED_ROUND,\n        new ABadgeMenuItemClickListener() {\n            @Override\n            public void onOptionsItemSelected(MenuItem menuItem) {\n                if (menuItem.getItemId() == R.id.drawer_menu_item1) {\n                    Toast.makeText(DrawerActivity.this, \"自定义监听 ==\u003e 点击了按钮2\", Toast.LENGTH_SHORT).show();\n                }\n            }\n        });\n\n    new ABadgeMenuItemHelper(DrawerActivity.this).show(\n        menuItem2,\n        getResources().getDrawable(R.mipmap.tab_me_normal),\n        getResources().getDrawable(R.mipmap.tab_me_checked),\n        100,\n        ABadgeStyleDefault.RED_ROUND_RECT,\n        new ABadgeMenuItemClickListener() {\n            @Override\n            public void onOptionsItemSelected(MenuItem menuItem) {\n                if (menuItem.getItemId() == R.id.drawer_menu_item2) {\n                    Toast.makeText(DrawerActivity.this, \"自定义监听 ==\u003e 点击了按钮2\", Toast.LENGTH_SHORT).show();\n                }\n            }\n        });\n\n    new ABadgeMenuItemHelper(DrawerActivity.this).show(\n        menuItem3,\n        getResources().getDrawable(R.drawable.ic_home_black_24dp),\n        getResources().getDrawable(R.drawable.ic_home_black_24dp),\n        \"测试\",\n        ABadgeStyleDefault.RED_ROUND_RECT,\n        new ABadgeMenuItemClickListener() {\n            @Override\n            public void onOptionsItemSelected(MenuItem menuItem) {\n                if (menuItem.getItemId() == R.id.drawer_menu_item3) {\n                    Toast.makeText(DrawerActivity.this, \"自定义监听 ==\u003e 点击了按钮3\", Toast.LENGTH_SHORT).show();\n                }\n            }\n        });\n```\n\n----\n\n## Thanks\n\nABadgeView: reference: 'q.rorbin:badgeview:1.1.3'\n\n**ABadge annotation and compiler** reference: [BGABadgeView-Android](https://github.com/bingoogolapple/BGABadgeView-Android)\n\n**Toolbar show badge** reference:  [Android-ActionItemBadge](https://github.com/mikepenz/Android-ActionItemBadge)\n\n----\n\n## License\n\n    Copyright 2023 AWeiLoveAndroid\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n       http://www.apache.org/licenses/LICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweiloveandroid%2Fabadgeview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faweiloveandroid%2Fabadgeview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faweiloveandroid%2Fabadgeview/lists"}