2024年HarmonyOS鸿蒙最新鸿蒙HarmonyOS实战-ArkUI组件(Button)_鸿蒙 button,2024年最新腾讯面试题java

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

Button(label?: string, options?: { type?: ButtonType, stateEffect?: boolean })
Button(options?: {type?: ButtonType, stateEffect?: boolean})

使用:

@Entry
@Component
struct Index {
build() {
Column(){
Button(‘Ok’, { type: ButtonType.Normal, stateEffect: true })
.borderRadius(8)
.backgroundColor(0x317aff)
.width(90)
.height(40)
Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() {
Image($r(‘app.media.app_icon’)).width(20).height(40).margin({ left: 12 })
Text(‘loading’).fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
}.alignItems(VerticalAlign.Center)
}.borderRadius(8).backgroundColor(0x317aff).width(90).height(40)
}
}
}

在这里插入图片描述

2.设置按钮类型

@Entry
@Component
struct Index {
build() {
Column(){
Button(‘Disable’, { type: ButtonType.Capsule, stateEffect: false })
.backgroundColor(0x317aff)
.width(90)
.height(40)
Button(‘Circle’, { type: ButtonType.Circle, stateEffect: false })
.backgroundColor(0x317aff)
.width(90)
.height(90)
Button(‘Circle’, { type: ButtonType.Normal, stateEffect: false })
.backgroundColor(0x317aff)
.width(90)
.height(90)
}
}
}

在这里插入图片描述

注意:不支持通过borderRadius属性重新设置

3.自定义样式

@Entry
@Component
struct Index {
build() {
Column(){
Button(‘circle border’, { type: ButtonType.Normal })
.borderRadius(20)
.height(40)
Button(‘font style’, { type: ButtonType.Normal })
.fontSize(20)
.fontColor(Color.Pink)
.fontWeight(800)
Button(‘background color’).backgroundColor(0xF55A42)
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r(‘app.media.ic_public_refresh’)).width(30).height(30)
}.width(55).height(55).margin({ left: 20 }).backgroundColor(0xF55A42)
}
}
}

在这里插入图片描述

4.添加事件

Button(‘Ok’, { type: ButtonType.Normal, stateEffect: true })
.onClick(()=>{
console.info(‘Button onClick’)
})

5.案例

Button按钮的实际应用场景主要包括以下几个方面:

  1. 点击提交表单
    当用户填写完表单后,点击Button按钮来提交表单数据,使得数据能够被服务器端处理或者保存到数据库中。
  2. 跳转链接
    当用户点击Button按钮时,跳转到指定的网页、应用程序或者其他页面。
  3. 打开或关闭弹窗
    当用户点击Button按钮时,打开或关闭弹窗,可以在弹窗中展示一些信息、广告或者提示。
  4. 执行某个动作
    当用户点击Button按钮时,执行某个操作,比如刷新页面、播放音乐、暂停视频等。
  5. 切换页面状态
    当用户点击Button按钮时,可以切换页面的状态,比如打开或关闭菜单、切换语言、切换主题等。

Button按钮的应用场景非常广泛,基本上所有需要用户交互的场景都可以使用Button按钮来实现。

🦋2.1 页面跳转

// xxx.ets
import router from ‘@ohos.router’;
@Entry
@Component
struct ButtonCase1 {
build() {
List({ space: 4 }) {
ListItem() {
Button(“First”).onClick(() => {
router.pushUrl({ url: ‘pages/first_page’ })
})
.width(‘100%’)
}
ListItem() {
Button(“Second”).onClick(() => {
router.pushUrl({ url: ‘pages/second_page’ })
})
.width(‘100%’)
}
ListItem() {
Button(“Third”).onClick(() => {
router.pushUrl({ url: ‘pages/third_page’ })
})
.width(‘100%’)
}
}
.listDirection(Axis.Vertical)
.backgroundColor(0xDCDCDC).padding(20)
}
}

在这里插入图片描述

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

需要这份系统化的资料的朋友,可以戳这里获取*

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 25
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值