#鸿蒙通关秘籍#能否通过Radio实现声音模式的切换?

HarmonyOS
2024-12-04 14:19:35
968浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
时光旅人NoSQL

可以通过Radio组件来切换不同的声音模式,结合onChange事件,实现触发不同模式的改变。以下是一段实现声音模式切换的代码示例:

import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct RadioExample {
  @State Rst:promptAction.ShowToastOptions = {'message': 'Ringing mode.'}
  @State Vst:promptAction.ShowToastOptions = {'message': 'Vibration mode.'}
  @State Sst:promptAction.ShowToastOptions = {'message': 'Silent mode.'}
  
  build() {
    Row() {
      // 响铃模式
      Column() {
        Radio({ value: 'Radio1', group: 'radioGroup' }).checked(true)
        .height(50)
        .width(50)
        .onChange((isChecked: boolean) => {
          if(isChecked) {
            promptAction.showToast(this.Rst)
          }
        })
        Text('Ringing')
      }
      // 振动模式
      Column() {
        Radio({ value: 'Radio2', group: 'radioGroup' })
        .height(50)
        .width(50)
        .onChange((isChecked: boolean) => {
          if(isChecked) {
            promptAction.showToast(this.Vst)
          }
        })
        Text('Vibration')
      }
      // 静音模式
      Column() {
        Radio({ value: 'Radio3', group: 'radioGroup' })
        .height(50)
        .width(50)
        .onChange((isChecked: boolean) => {
          if(isChecked) {
            promptAction.showToast(this.Sst)
          }
        })
        Text('Silent')
      }
    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
分享
微博
QQ
微信
回复
2024-12-04 16:29:39
相关问题