解决android中icon只能使用一张icon的问题

本文介绍如何在Ionic应用中实现Tab图标根据条件动态变化的效果,包括HTML结构绑定及TS逻辑处理,配合自定义CSS样式实现不同状态下的图标显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.html 中 绑定 ionselect的方法,tabicon使用变量

<ion-tabs>
<ion-tab [root]="tab1Root" (ionSelect)="change(0)" [tabTitle]="tab1Title" tabIcon="{{wenzhen}}"></ion-tab>
<ion-tab [root]="tab2Root" (ionSelect)="change(1)" [tabTitle]="tab2Title" tabIcon="{{huanzhe}}"></ion-tab>
<ion-tab [root]="tab3Root" (ionSelect)="change(2)" [tabTitle]="tab3Title" tabIcon="{{wode}}"></ion-tab>
</ion-tabs>


.ts 中

import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { IonicPage, NavController, Platform } from 'ionic-angular';

import { Tab1Root } from '../pages';
import { Tab2Root } from '../pages';
import { Tab3Root } from '../pages';

@IonicPage()
@Component({
selector: 'page-tabs',
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root: any = Tab1Root;
tab2Root: any = Tab2Root;
tab3Root: any = Tab3Root;

tab1Title = " ";
tab2Title = " ";
tab3Title = " ";

wenzhen = "wenzhen";
huanzhe = "huanzhe";
wode = "wode";

constructor(public navCtrl: NavController, public translateService: TranslateService, public platform: Platform) {
translateService.get(['TAB1_TITLE', 'TAB2_TITLE', 'TAB3_TITLE']).subscribe(values => {
this.tab1Title = values['TAB1_TITLE'];
this.tab2Title = values['TAB2_TITLE'];
this.tab3Title = values['TAB3_TITLE'];
});
}

change(a: number) {
if (this.platform.is("android")) {
if(a==0){
this.wenzhen = "wenzhenandroid";
this.huanzhe = "huanzhe";
this.wode = "wode";
}else if(a==1){
this.wenzhen = "wenzhen";
this.huanzhe = "huanzheandroid";
this.wode = "wode";
}else if(a==2){
this.wenzhen = "wenzhen";
this.huanzhe = "huanzhe";
this.wode = "wodeandroid";
}
}
}


}


自定义css icon

.ion-ios-wenzhen:before {
@include font-size-custom;
background: no-repeat url('../assets/imgs/wenzhenbefore.png');
}

.ion-ios-wenzhen-outline {
@include font-size-custom;
background: no-repeat url('../assets/imgs/wenzhen.png');
}

.ion-md-wenzhen {
@include font-size-custom;
background: no-repeat url('../assets/imgs/wenzhen.png');
}

.ion-md-wenzhenandroid:before {
@include font-size-custom;
background: no-repeat url('../assets/imgs/wenzhenbefore.png');
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值