harmony-utils之ToastUtil,吐司工具类
harmony-utils 简介与说明
[harmony-utils] 一款功能丰富且极易上手的HarmonyOS工具库,借助众多实用工具类,致力于助力开发者迅速构建鸿蒙应用。其封装的工具涵盖了APP、设备、屏幕、授权、通知、线程间通信、弹框、吐司、生物认证、用户首选项、拍照、相册、扫码、文件、日志,异常捕获、字符、字符串、数字、集合、日期、随机、base64、加密、解密、JSON等一系列的功能和操作,能够满足各种不同的开发需求。
[picker_utils] 是harmony-utils拆分出来的一个子库,包含PickerUtil、PhotoHelper、ScanUtil。
下载安装ohpm i @pura/harmony-utils
ohpm i @pura/picker_utils
//全局初始化方法,在UIAbility的onCreate方法中初始化 AppUtil.init()
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
AppUtil.init(this.context);
}
API方法与使用
setDefaultConfig 设置默认统一样式
ToastUtil.setDefaultConfig((config) = > {
config.alignment = Alignment.Top
config.offset = { dx: 0, dy: 80 }
config.backgroundColor = Color.Red
config.textColor = Color.White
config.enableHoverMode = true
config.hoverModeArea = HoverModeAreaType.BOTTOM_SCREEN
});
ToastUtil.setDefaultConfig((config) = > {
config.alignment = Alignment.Center
config.offset = { dx: 0, dy: 0 }
config.showMode = promptAction.ToastShowMode.DEFAULT
config.duration = 2600
config.backgroundColor = Color.Blue
config.textColor = Color.White
config.enableHoverMode = true
config.hoverModeArea = HoverModeAreaType.TOP_SCREEN
});
showToast 弹出吐司,默认时长为2s
ToastUtil.showToast("弹出土司,默认时长为2s");
ToastUtil.showToast("弹出土司,当前样式", {
alignment: Alignment.Center,
offset: { dx: 0, dy: -100 },
backgroundColor: '#669900'
});
ToastUtil.showToast("弹出土司,当前样式", {
alignment: Alignment.Center,
backgroundColor: '#00AA88',
textColor: Color.Pink,
duration: 6000
});
showShort 弹出短吐司,默认时长为:1.5s
ToastUtil.showShort("弹出短土司,时长为:1.5s");
showLong 弹出长吐司,默认时长为:10s
ToastUtil.showLong("弹出短土司,时长为:10s");
创作不易,请给童长老点赞
审核编辑 黄宇
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
Harmony
+关注
关注
0文章
108浏览量
3107
发布评论请先 登录
相关推荐
热点推荐
harmony-utils之LRUCacheUtil,LRUCache缓存工具类
harmony-utils之LRUCacheUtil,LRUCache缓存工具类 harmony-utils 简介与说明
harmony-utils之NumberUtil,Number工具类
harmony-utils之NumberUtil,Number工具类 harmony-utils 简介与说明
harmony-utils之PreferencesUtil,首选项工具类
harmony-utils之PreferencesUtil,首选项工具类 harmony-utils 简介与说明 [
harmony-utils之PreviewUtil,文件预览工具类
harmony-utils之PreviewUtil,文件预览工具类 harmony-utils 简介与说明 [
harmony-utils之SnapshotUtil,截图相关工具类
harmony-utils之SnapshotUtil,截图相关工具类 harmony-utils 简介与说明 [
harmony-utils之StrUtil,字符串工具类
harmony-utils之StrUtil,字符串工具类 harmony-utils 简介与说明 [ha
harmony-utils之TypeUtil,类型检查工具类
harmony-utils之TypeUtil,类型检查工具类 harmony-utils 简介与说明 [
harmony-utils之AuthUtil,生物认证相关工具类
# harmony-utils之AuthUtil,生物认证相关工具类 ## harmony-utils 简介与说明 ------[
harmony-utils之ArrayUtil,集合工具类
# harmony-utils之ArrayUtil,集合工具类 ## harmony-utils 简介与说明 ------[
评论