# Ohos-ActionItemBadge **Repository Path**: chinasoft5_ohos/Ohos-ActionItemBadge ## Basic Information - **Project Name**: Ohos-ActionItemBadge - **Description**: 简便易用的徽标 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-21 - **Last Updated**: 2021-12-13 ## Categories & Tags **Categories**: harmonyos-textview **Tags**: None ## README # Ohos-ActionItemBadge #### 项目介绍 - 项目名称:Ohos-ActionItemBadge - 所属系列:openharmony第三方组件适配移植 - 功能:简便易用的徽标 - 项目移植状态:主功能完成 - 调用差异:有(更新menu变为更新布局, 缺少调用原第三方库操作) - 开发版本:sdk6,DevEco Studio2.2 Beta1 - 基线版本:Release v4.0.0 #### 效果演示 ![sc1](https://gitee.com/chinasoft5_ohos/Ohos-ActionItemBadge/raw/main/showpic/lupin2.gif) ![sc1](https://gitee.com/chinasoft5_ohos/Ohos-ActionItemBadge/raw/main/showpic/lupin3.gif) #### 安装教程 1.在项目根目录下的build.gradle文件中, ``` repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } ``` 2.在entry模块的build.gradle文件中, ``` dependencies { implementation 'com.gitee.chinasoft_ohos:ohos_actionitembadge:1.0.0' } ``` 在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 ```xml // ohos:layout 中ohos:layout="$layout:menu_action_item_badge" 必须要引用 ``` * Java 调用示例 ```java // step1 : // 实现 ListLeftAdapter.ItemOnClickListener,ActionItemBadge.ActionItemBadgeListener, ActionItemBadge.ActionItemBadgeLongListener // 第一个是左侧抽屉style切换监控, 第二个是普通点击徽标事件, 第三个是长按徽标事件 public class MainAbilitySlice extends AbilitySlice implements ListLeftAdapter.ItemOnClickListener, ActionItemBadge.ActionItemBadgeListener, ActionItemBadge.ActionItemBadgeLongListener{ } //进行事件绑定 ListLeftAdapter leftAdapter = new ListLeftAdapter(MainAbilitySlice.this, leftList);//left数据自己填充 leftAdapter.setmItemOnClickListener(this::itemOnClickListener); ActionItemBadge.setMyListener(this); ActionItemBadge.setLongClickListener(this); // 父控件 (一般是某种布局) toolbar_dependentLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_toolbar_dependentLayout); //下面的是存储角标的布局 component01 = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_main,null,false); // 用toolbar_dependentLayout 添加component01 toolbar_dependentLayout.addComponent(component01); // 需要徽标的布局 Component c01= component01.findComponentById(ResourceTable.Id_item_samplebadge); // step2 : // 进行库更新徽标调用 slice 为当前的AbilitySlice, 第二个值即徽标布局(也可用上面c01替代), 第三个为系统徽标图形, 第四个style为徽标款式类型, 第五个为徽标上显示的文本 ActionItemBadge.update(slice,component01.findComponentById(ResourceTable.Id_item_samplebadge),FontAwesome.Icon.faw_cloud_sun,nstyle,badgeCount); // step3: //点击侧滑按钮 @Override public void itemOnClickListener(int position) { if (leftList != null && leftList.size() > 0) { changePosition(position); } } // 长按徽标 @Override public boolean onOptionsItemLongSelected(Component component) { int id = component.getId(); if (id == ResourceTable.Id_item_samplebadge) { } return false; } //单击徽标 @Override public boolean onOptionsItemSelected(Component component) { int id = component.getId(); if (id == ResourceTable.Id_item_samplebadge) { badgeCount --; if (badgeCount>0){ ActionItemBadge.update(component02,badgeCount); }else{ ActionItemBadge.hide(component02); } } return false; } ``` ### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 ### 版本迭代 - 1.0.0 ### 版权和许可信息 Copyright 2019 Mike Penz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.