HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio

单选框,提供相应的用户交互选择项。该组件从API Version 8开始支持。无子组件。
一、接口
Radio(options: {value: string, group: string})
从API version 9开始,该接口支持在ArkTS卡片中使用。
参数:
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第1张图片


二、属性
除支持通用属性外,还支持以下属性:
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第2张图片


三、事件
除支持通用事件外,还支持以下事件:
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第3张图片


四、示例

// xxx.ets
@Entry
@Component
struct RadioExample {
  build() {
    Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
      Column() {
        Text('Radio1')
        Radio({ value: 'Radio1', group: 'radioGroup' }).checked(true)
          .height(50)
          .width(50)
          .onChange((isChecked: boolean) => {
            console.log('Radio1 status is ' + isChecked)
          })
      }
      Column() {
        Text('Radio2')
        Radio({ value: 'Radio2', group: 'radioGroup' }).checked(false)
          .height(50)
          .width(50)
          .onChange((isChecked: boolean) => {
            console.log('Radio2 status is ' + isChecked)
          })
      }
      Column() {
        Text('Radio3')
        Radio({ value: 'Radio3', group: 'radioGroup' }).checked(false)
          .height(50)
          .width(50)
          .onChange((isChecked: boolean) => {
            console.log('Radio3 status is ' + isChecked)
          })
      }
    }.padding({ top: 30 })
  }
}

复制

五、效果
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第4张图片

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第5张图片

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Radio_第6张图片

六、场景
适合卡片上直接操作单选项的场景。

本文根据HarmonyOS官方文档整理。

你可能感兴趣的:(华为,HarmonyOS)