# hr-number-add-sub **Repository Path**: Hancher/hr-number-add-sub ## Basic Information - **Project Name**: hr-number-add-sub - **Description**: No description available - **Primary Language**: Android - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-08-13 - **Last Updated**: 2026-01-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 数字加减组件 这是一个Android平台的数字加减组件库,包含数字输入键盘弹窗功能。 # 功能特点 - 提供数字加减按钮组件 - 支持点击数字显示键盘弹窗 - 包含两种不同样式的键盘弹窗 - 支持最大值/最小值限制 - 支持数字格式化处理 # 主要组件 ## HrNumberAddSub 数字加减主组件,继承自RelativeLayout,包含: - 加减按钮 - 数字显示文本 - 支持设置最大/最小值 - 提供数字变化监听器 ![HrNumberAddSub控件](https://imgtu.com/uploads/xl6k3zg1/Screenshot_2025-09-21_17-00-52.png) 在XML布局中使用: ```xml ``` ## HrNumberKeyboardPopup & HrNumberKeyboardPopup2 两种不同样式的数字键盘弹窗: - 支持数字输入 - 支持小数点输入 - 限制最大输入位数 - 支持删除操作 - 提供确认按钮 ![HrNumberKeyboardPopup控件](https://imgtu.com/uploads/xl7gmbr6/Screenshot_2025-09-21_17-02-06.png) ![HrNumberKeyboardPopup2控件](https://imgtu.com/uploads/xl81eaxo/Screenshot_2025-09-21_17-02-23.png) 在Java代码中设置弹窗: ```java public void showKeyboard() { // 默认样式 new XPopup.Builder(MainActivity.this) .isCenterHorizontal(true) .isDestroyOnDismiss(true) .popupWidth(200) .popupHeight(400) .asCustom(new HrNumberKeyboardPopup2(MainActivity.this, new HrNumberKeyboardPopup2.OnViewClickListener() { @Override public void afterNumberChanged(String s) { } @Override public void onComplete(double lastNum) { } })) .show(); // 3位小数,默认null,最大输入7位 new XPopup.Builder(StoreReturnOperateActivity.this) .isCenterHorizontal(true) .isDestroyOnDismiss(true) .popupWidth(llContainer.getWidth() * 2 / 3) .popupHeight(llContainer.getHeight() / 2) .asCustom(new HrNumberKeyboardPopup2(StoreReturnOperateActivity.this, new HrNumberKeyboardPopup2.OnViewClickListener() { @Override public void afterNumberChanged(String s) { } @Override public void onComplete(double lastNum) { updateDetail(item, BigDecimal.valueOf(lastNum), item.getRemark(), item.getOnePicKey(), item.getOnePicUrl()); } }, 3, null, 7)) .show(); } ``` ## HrNumberAddSubUtil 数字处理工具类,提供: - 加法操作 - 减法操作 - 数值范围限制 - 数字格式化 ```java public void operation() { if (view.getId() == R.id.iv_reduce) { updateDetail(item, HrNumberAddSubUtil.subNum(item.getProductNum(), BigDecimal.ONE, null, BigDecimal.ZERO, 0)); } else if (view.getId() == R.id.iv_add) { updateDetail(item, HrNumberAddSubUtil.addNum(item.getProductNum(), BigDecimal.ONE, null, BigDecimal.ZERO, 0)); } } ``` # 依赖库 - XPopup:用于实现弹窗效果 - AndroidX:使用AndroidX支持库 # 许可证 本项目使用MIT许可证,请参见LICENSE文件。