$rawfile方式参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...字体文件放置路径:src/main/resources/rawfile/font/gealova.otf代码中引用示例:font.registerFont({ familyName: 'Gealova', familySrc: $rawfile('font/gealova.otf') })在EntryAbility的onWindowStageCreate中注册字体,在模拟器上运行://EntryAbility的onWindowStageCreate中: windowStage.getMainWindow().then(res=>{ //注册字体 const uiCtc=res.getUIContext() uiCtc.getFont().registerFont({ familyName:'mediumRawFile', familySrc:$rawfile('font/BLACKTW-Bold.otf') }) uiCtc.getFont().registerFont({ familyName:'twrafile', familySrc:$rawfile('font/TW-Bold.otf') }) }) //index.ets @Entry @Component struct index{ @State message: string = 'Hello World' build() { Column() { Text(this.message) .align(Alignment.Center) .fontSize(20) .fontFamily('mediumRawFile') // mediumRawFile:注册自定义字体的名字 Text('eeeee') .align(Alignment.Center) .fontSize(20) .fontFamily('twrafile') }.width('100%') } }
$rawfile方式参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
字体文件放置路径:src/main/resources/rawfile/font/gealova.otf
代码中引用示例:
在EntryAbility的onWindowStageCreate中注册字体,在模拟器上运行: