我有一个带有Tabview的Nativescript Angular应用。我想在需要采取措施的选项卡上放置一个徽章。在iOS上,我成功做到了这一点,但是在android上,我没有做到这一点。我找到了这个线程:https://discourse.nativescript.org/t/nativescript-android-add-badge-on-tabview-tabs/4768,但这对我没有帮助。也许这不再适用于Nativescript 5.x ...
我正在使用此代码来更改标签视图。除了android setBadge部分,其他所有东西都可以正常工作。
import { TabView } from "tns-core-modules/ui/tab-view/tab-view";
import { isAndroid, isIOS } from "tns-core-modules/platform/platform";
export class TabViewService {
private TabView: TabView;
private androidInitialHeight;
setTabView(tabview: TabView) {
this.TabView = tabview;
console.log("TABVIEW SET");
if (isAndroid) {
const tabLayout = this.TabView.nativeViewProtected.tabLayout;
this.androidInitialHeight = tabLayout.getLayoutParams().height;
}
}
getTabView() {
return this.TabView;
}
hideTabView() {
console.log("HIDING TABVIEW");
if (isIOS) {
this.TabView.viewController.tabBar.hidden = true;
}
if (isAndroid) {
const tabLayout = this.TabView.nativeViewProtected.tabLayout;
tabLayout.getLayoutParams().height = 0;
tabLayout.requestLayout();
}
}
showTabView() {
console.log("SHOWING TABVIEW");
if (isIOS) {
this.TabView.viewController.tabBar.hidden = false;
}
if (isAndroid) {
const tabLayout = this.TabView.nativeViewProtected.tabLayout;
tabLayout.getLayoutParams().height = this.androidInitialHeight;
tabLayout.requestLayout();
}
}
setBadgeValue(tabIndex: number, value: number) {
value = value === 0 ? null : value;
console.log("SETTING BADGE VALUE OF INDEX: " + tabIndex);
if (isIOS) {
const tabItem = this.TabView.ios.tabBar.items[tabIndex];
tabItem.badgeValue = value.toString();
}
if (isAndroid) {
}
}
}
有人给我小费吗?