通过$r访问应用资源是否支持嵌套形式?

通过$r访问应用资源是否支持嵌套形式

阅读 541
1 个回答

解决措施

$r当前不支持嵌套,第二个参数需要使用ResourceManager获取应用资源对应字符串赋值给$r第二个参数。

代码示例

import { common } from '@kit.AbilityKit'; 
 
@Entry 
@Component 
struct Page16 { 
  private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 
 
  build() { 
    Row() { 
      Column() { 
        Text($r('app.string.EntryAbility1_label2', 
          this.context.resourceManager.getStringSync($r('app.string.EntryAbility_label'))))//resources\base\element\string.json 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}

参考链接

ResourceManager

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进