#鸿蒙学习大百科#如果应用有多个UIAbility,如何判断当前app进入了后台的状态?
使用ApplicationContext.on()来监听每个UIAbility的状态,当每个UIAbility都进入了后台状态,那么app进入后台。letAbilityLifecycleCallback:AbilityLifecycleCallback{onAbilityBackground(ability){},onAbilityCreate:(ability:UIAbility):void>{thrownewError('Functionnotimplemented.');},onWindowStageCreate:(ability:UIAbility,windowStage:window.WindowStage):void>{thrownewError('Functionnotimplemented.');},onWi...
#鸿蒙学习大百科#从哪里去下载常用的三方库?
https:gitee.comopenharmonytpctpcresourcefromgiteesearch%E4%B8%89%E6%96%B9%E7%BB%84%E4%BB%B6%E8%B5%84%E6%BA%90%E6%B1%87%E6%80%BB针对三方库做了汇总。通过ohpm工具可以直接获取。
#鸿蒙学习大百科#如何将资源对象转成string类型?
import{resourceManager}from'kit.LocalizationKit';import{BusinessError}from'kit.BasicServicesKit';try{letsystemResourceManagerresourceManager.getSystemResourceManager();systemResourceManager.getStringValue($r('sys.string.ohoslabvibrate').id).then((value:string)>{console.info("sys.string.ohoslabvibratevalueis"+value);}).catch((error:BusinessError)>{console.error(systemResourceManagergetStringValu...
#鸿蒙学习大百科#如何获取系统语言、系统地区、系统区域?
import{i18n}from'kit.LocalizationKit';EntryComponentstructIndex{build(){Column(){Button("点击").onClick(()>{获取系统语言letsystemLanguagei18n.System.getSystemLanguage();systemLanguage为当前系统语言console.log("语言:"+systemLanguage)获取系统地区letsystemRegioni18n.System.getSystemRegion();systemRegion为当前系统地区console.log("地区:"+systemRegion)获取系统区域letsystemLocalei18n.System.getSystemLocale();systemLocale为当前系统区域console.log("区域:"+systemLocale)})}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#如果空间不足如何显示简短的时间信息?
导入模块import{intl}from'kit.LocalizationKit';EntryComponentstructIndex{Statetime:string''build(){Column(){Text(this.time).fontSize(20).margin(10)Button("点击").onClick(()>{设置要格式化的日期letdatenewDate(2021,8,17,13,4,0);letdateFormat2newintl.DateTimeFormat('zhCN',{dateStyle:'short',timeStyle:'short'});this.timedateFormat2.format(date);formattedDate2:202191713:04})}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#如何将一个数字转化为科学计数法显示?
导入模块import{intl}from'kit.LocalizationKit';EntryComponentstructIndex{Statestr:string''build(){Column(){Text(this.str).fontSize(30).margin(20)Button("点击").onClick(()>{用科学计数法显示数字letnumberFormat1newintl.NumberFormat('zhCN',{notation:'scientific',maximumSignificantDigits:3});this.strnumberFormat1.format(123400);formattedNumber1:1.23E5})}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#如何将小数转化为百分比?
导入模块import{intl}from'kit.LocalizationKit';EntryComponentstructIndex{Statestr:string''aboutToAppear():void{显示百分数letnumberFormat4newintl.NumberFormat('zhCN',{style:'percent'});this.strnumberFormat4.format(0.25);formattedNumber4:25%}build(){Column(){Text(this.str).fontSize(30).margin(20)}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#如何将电话号码显示为RFC3966类型的电话号码?
导入模块import{i18n}from'kit.LocalizationKit';EntryComponentstructIndex{Statestr:string''aboutToAppear():void{RFC3966类型的电话号码letphoneNumberFormat2newi18n.PhoneNumberFormat('CN',{type:'RFC3966'});this.strphoneNumberFormat2.format('1582312');formattedPhoneNumber2:tel:+861582312}build(){Column(){Text(this.str).fontSize(30).margin(20)}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#如何判断一个字符是不是数字?
导入模块import{i18n}from'kit.LocalizationKit';EntryComponentstructIndex{StateisDigit:booleanfalseaboutToAppear():void{判断字符是否是数字,必须是一个字符this.isDigiti18n.Unicode.isDigit('2');}build(){Column(){Text(this.isDigit"是数字":"不是数字").fontSize(30).margin(20)}.height("100%").width('100%').justifyContent(FlexAlign.Center)}}
#鸿蒙学习大百科#Stage模型下如何获取首选项实例?
importUIAbilityfrom'ohos.app.ability.UIAbility';import{BusinessError}from'ohos.base';importwindowfrom'ohos.window';importdataPreferencesfrom'ohos.data.preferences';onWindowStageCreate(windowStage:window.WindowStage):void{letoptions:dataPreferences.Options{name:'myStore'};letpreferencesdataPreferences.getPreferencesSync(this.context,options)}
#鸿蒙学习大百科#如何实现登录按钮LoginWithHuaweiIDButton登录?
import{BusinessError}from'kit.BasicServicesKit';import{hilog}from'kit.PerformanceAnalysisKit';import{loginComponentManager}from'kit.AccountKit';import{LoginWithHuaweiIDButton}from'kit.AccountKit';EntryComponentstructIndex{构造LoginWithHuaweiIDButton组件的控制器controller:loginComponentManager.LoginWithHuaweiIDButtonControllernewloginComponentManager.LoginWithHuaweiIDButtonController().onClickLo...