云象智能科技有限公司
发表于 2022-1-10 22:48:05
本帖最后由 云象智能科技有限公司 于 2022-1-13 17:01 编辑
ios清楚角标无效,以下两种方式都测试了
NVTabBar.setBadge({
index: index,
badge: 0
});
NVTabBar.setBadge({
index: index,
});
场景描述:
待办业务,处理完一个任务后,角标数字减一,当最后一个处理完后,无法清除角标,一直显示1,除非退出app重新打开。
完整代码:
api.addEventListener({
name: 'IndexSetBadgeEvent'
}, function(ret, err) {
var index = ret.value.index;
var badge = Number(ret.value.badge);
var NVTabBar = api.require('NVTabBar');
if (badge > 0) {
var horizentalPadding = "5";
if (badge > 9) {
horizentalPadding = "2";
}
NVTabBar.setBadge({
index: index,
horizentalPadding: horizentalPadding,
badge: badge
});
} else {
showAlert("setBadge 0");
// NVTabBar.setBadge({
// index: index,
// badge: 0
// });
NVTabBar.setBadge({
index: index,
});
}
});
新建空白项目:也是不能清除数字角标
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="./css/api.css" />
<link rel="stylesheet" type="text/css" href="./css/aui.css" />
<link rel="stylesheet" type="text/css" href="./css/iconfont.css" />
<style type="text/css">
html,
body {
height: 100%;
}
.wrap {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-flex-flow: column;
}
header {
height: 44px;
width: 100%;
text-align: center;
background-color: #81a9c3;
color: #fff;
line-height: 44px;
font-size: 20px;
}
.flex-1 {
-webkit-box-flex: 1;
-webkit-flex: 1;
}
footer {
height: 30px;
width: 100%;
background-color: #81a9c3;
color: white;
line-height: 30px;
text-align: center;
}
</style>
</head>
<body class="wrap">
<section class="flex-1">
<div style="padding:20px;text-align:center;padding-top:100px"> <div id="num" style="width:100%;margin-bottom:10px">0</div>
<div class="aui-btn" tapmode style="width:100%;margin-bottom:10px;height:50px;line-height:50px">+1</div>
<div class="aui-btn" tapmode style="width:100%;margin-bottom:10px;height:50px;line-height:50px">清空</div>
</div>
</section>
<footer>Copyright ©<span id="year"></span></footer>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
apiready = function() {
//输出Log,Log将显示在APICloud Studio控制台
console.log("Hello World! Hello APICloud!");
initTabBar();
};
function initTabBar() {
var arr = [];
var w = api.winWidth / 5.0;
var marginB = -15;
var platform = api.systemType;
if (platform == "android") {
marginB = -5;
}
var items = [{
w: w,
iconRect: {
w: 22.0,
h: 22.0,
},
icon: {
normal: 'widget://image/tab_home.png',
highlight: 'widget://image/tab_home_ac.png',
selected: 'widget://image/tab_home_ac.png'
},
title: {
text: '首页',
size: 12.0,
normal: '#bfbfbf',
selected: '#FF9600',
marginB: 2
},
bg: {
marginB: marginB,
image: 'rgba(200,200,200,0)'
}
}, {
w: w,
iconRect: {
w: 23.0,
h: 23.0,
},
icon: {
normal: 'widget://image/tab_todo.png',
highlight: 'widget://image/tab_todo_ac.png',
selected: 'widget://image/tab_todo_ac.png'
},
title: {
text: '待办',
size: 12.0,
normal: '#bfbfbf',
selected: '#FF9600',
marginB: 2.0
},
bg: {
marginB: marginB,
image: 'rgba(200,200,200,0)'
}
}, {
w: w,
icon: {
normal: 'widget://image/tab_add.png',
highlight: 'widget://image/tab_add.png',
selected: 'widget://image/tab_add.png'
},
iconRect: {
w: 40,
h: 40
},
bg: {
marginB: marginB,
image: 'rgba(200,200,200,0)'
}
}, {
w: w,
iconRect: {
w: 22.0,
h: 22.0,
},
icon: {
normal: 'widget://image/tab_square.png',
highlight: 'widget://image/tab_square_ac.png',
selected: 'widget://image/tab_square_ac.png'
},
title: {
text: '广场',
size: 12.0,
normal: '#bfbfbf',
selected: '#FF9600',
marginB: 2
},
bg: {
marginB: marginB,
image: 'rgba(200,200,200,0)'
}
}, {
w: w,
iconRect: {
w: 22.0,
h: 22.0,
},
icon: {
normal: 'widget://image/tab_mine.png',
highlight: 'widget://image/tab_mine_ac.png',
selected: 'widget://image/tab_mine_ac.png'
},
title: {
text: '我的',
size: 12.0,
normal: '#bfbfbf',
selected: '#FF9600',
marginB: 2.0
},
bg: {
marginB: marginB,
image: 'rgba(200,200,200,0)'
}
}
];
var NVTabBar = api.require('NVTabBar');
NVTabBar.open({
cursorInOptions: {
width: w, //游标的宽
height: 50, //游标的高
color: 'widget://image/tab_bg.png' //游标的颜色,支持图片
},
styles: {
bg: 'widget://image/tabbar_bg.png',
// bg: 'rgba(200,200,200,1)',
h: 65,
dividingLine: {
width: 0,
color: '#1CC5A3'
},
badge: {
bgColor: '#ff0000',
numColor: '#fff',
size: 8.0,
rightMargin: 25,
fontSize: 8
// centerY: 6
}
},
items: items,
selectedIndex: 0
}, function(ret, err) {
var index = ret.index;
if (index == 0) {
} else if (index == 1) {
} else if (index == 2) {
} else if (index == 3) {
} else if (index == 4) {
}
})
}
function clear() {
$api.html($api.byId("num"), num);
var NVTabBar = api.require('NVTabBar');
NVTabBar.setBadge({
index: 1,
});
}
function inc() {
var num = Number($api.html($api.byId("num")));
num = num + 1;
$api.html($api.byId("num"), num);
var NVTabBar = api.require('NVTabBar');
NVTabBar.setBadge({
index: 1,
badge: num
});
}
</script>
</html>
|
|