HarmonyOS 如何设置App实现字体统一放大的老年模式,并且可以来回切换正常模式和大字模式 ?

HarmonyOS 如何设置App实现字体统一放大的老年模式,并且可以来回切换正常模式和大字模式 ?

阅读 637
1 个回答

你可以参考以下demo 使用Slider或者button来控制字体的放大和缩小,具体示例如下所示:

@Entry 
@Component 
struct Pagebutton { 
  @State imagewidth: number = 30; 
  @State fontwight: number = 30; 
  build() { 
 
    Column() { 
      Row(){ 
        Text($r('app.string.text')).fontSize(this.fontwight) 
        TextInput({placeholder:$r('app.string.image_width'),text:this.imagewidth.toString()}) 
          .type(InputType.Number) 
          .onChange(value=>{ 
            this.fontwight=parseInt(value) 
          }).backgroundColor('#fff') 
      }.justifyContent(FlexAlign.SpaceBetween).width('100%').padding({ 
        left:10, 
        right:10 
      }) 
      Divider().width('91%') 
      Row({space:10}){ 
        Button('点击增加字体大小').onClick(()=>{ 
 
          this.fontwight+=10 
        }) 
        Button('点击减少字体大小').onClick(()=>{ 
          this.fontwight-=10 
        }) 
      }.width('100%') 
      .justifyContent(FlexAlign.SpaceEvenly) 
      .margin({ 
        top:50 
      }) 
 
      Row(){ 
 
        Slider({ 
          min:0, 
          max:100, 
          value:this.imagewidth, 
          step:10, 
          style:SliderStyle.OutSet, 
          direction:Axis.Horizontal, 
          reverse:false 
        }).showTips(true).blockColor('#36d').onChange(value=>{ 
          console.log('value',value) 
          this.imagewidth=Math.trunc(value)//取整 
          console.log(typeof value) 
        }).trackThickness(10).width('100%') 
      }.margin({ 
        top:50 
      }) 
 
    } 
    .width('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题