当前位置: 首页 > news >正文

HarmonyOS ArkTS 实现类似Android中RadioButton得效果

在Android中如实现下图可以用radioGroup和RadioButton实现,但在ArkTs中radio不能实现自定义样式,所以用Tabs来实现这种效果,效果图如下:

一、效果图

在这里插入图片描述
在这里插入图片描述

二、实现横向布局的三个TabContent,代码如下

 @State currentIndex: number = 0;Row() {Tabs({ barPosition: BarPosition.Start }) {TabContent() {}.tabBar(this.TabBuilder('按钮1', 0))TabContent() {}.tabBar(this.TabBuilder('按钮2', 1));TabContent() {}.tabBar(this.TabBuilder('按钮3', 2))}.scrollable(false).barMode(BarMode.Fixed).barHeight(45)}.height(45).width('80%').margin({ top: 15, bottom: 15 }).backgroundColor($r('app.color.radio_button_no')).borderRadius(10).justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center)

三、TabContent单独得样式,样式可自定义字体颜色背景等,根据自己的需求进行调整

@Builder TabBuilder(title: string, index: number) {Column() {Text(title)// .margin({ top: $r('app.float.mainPage_baseTab_top') }).fontSize(16).fontWeight(FontWeight.Bold).fontColor(this.currentIndex === index ? $r('app.color.white') : $r('app.color.title_text_color'))}.justifyContent(FlexAlign.Center).height(43).height('90%').width(CommonConstants.FULL_PARENT).borderRadius(10).backgroundColor(this.currentIndex === index ? $r('app.color.radio_button_yes') : $r('app.color.radio_button_no')).onClick(() => {this.currentIndex = index;console.log('index-------' + index)})}

这样就实现了按钮切换的效果,如果还有其他更好的方法欢迎评论交流!!!

http://www.lryc.cn/news/350434.html

相关文章:

  • AWS简介
  • STM32的FLASH学习笔记
  • 人工智能-深度学习-PyTorch数据读取实战【含详细源代码+数据集+图示分析】
  • Qt常量字符串中文乱码QTextCodec转换无效
  • (五)Spring教程——Spring IoC容器(上)
  • TiDB学习1:TiDB体系架构概览
  • Prometheus 保留或删除标签 labeldrop、labelkeep
  • uniapp中实现保存图片,复制信息功能函数的封装
  • C#【进阶】委托和事件
  • 【class9】人工智能初步(处理单张图片)
  • cgicc开发 (结合jsoncpp)
  • HTML常用标签及属性
  • 【PB案例学习笔记】-03用户名密码校验
  • 设计模式六大原则之 接口分离原则
  • 嵌入式学习——Shell()——day21
  • STM32学习计划
  • 小米15曝光?可能会要稍微涨价
  • 深度优先搜索汇总
  • 【虚拟仿真】Unity3D中实现对大疆无人机遥控器手柄按键响应
  • Python学习之路 | Python基础语法(一)
  • 【已解决】AttributeError: module ‘clip‘ has no attribute ‘load‘
  • 安卓实现连接wesokcet
  • Xinstall助力App下载量精准统计,洞悉推广效果
  • CSS字体修饰
  • 高并发缓存服务的构建要点与陷阱
  • Electron学习笔记(五)
  • 【jest 调试 - vscode debug】
  • 华为OD机试【分奖金】(java)(100分)
  • 27- ESP32-S3 USB虚拟串口(USB-OTG 外设介绍)
  • PostgreSQL查看sql的执行计划