首页 > 其他分享 >【江鸟中原】ArkUI组件示例

【江鸟中原】ArkUI组件示例

时间:2023-12-23 17:33:40浏览次数:44  
标签:江鸟 name .. 示例 color app value State ArkUI

学习了一段鸿蒙课,觉得有必要晒一晒自己的进步。通过对ArkUI的学习,我学会了它主要分为基础组件、容器和弹窗。下面我主要对基础组件的按钮和文本进行分析,希望对学习鸿蒙开发的同学有帮助。

1.在DevEco Studio中创建一个新项目

2.在main下面的pages文件夹下建立ButtonPage.ets项目

项目代码如下:

import TitleTab from '../../component/title/TitleTab'
import Title from '../../component/title/Title'
import SelectCustom from '../../component/controller/SelectCustom'
import SwitchCustom from '../../component/controller/SwitchCustom'
import SliderCustom from '../../component/controller/SliderCustom'

@Entry
@Component
struct ButtonPage {
  @State selectTab: number = 1

  //type
  @State type: ButtonType = ButtonType.Capsule
  @State typeArr: ButtonType[] = [
  ButtonType.Capsule,
  ButtonType.Circle,
  ButtonType.Normal
  ]
  @State typeValueArr: { value: string }[] = [
    { value: 'Capsule' },
    { value: 'Circle' },
    { value: 'Normal' }
  ]

  //stateEffect
  @State stateEffect: boolean = true

  //width
  @State widthValue: number = 80

  //height
  @State heightValue: number = 50

  //fontSize
  @State sizeValue: number = 14

  @Builder pageTitle() {
    Column() {
      Title({ pageTitle: 'Button 按钮' })
      TitleTab({ selectTab: $selectTab, interface: false, property: true, common: true })
    }
    .width('100%')
    .backgroundColor($r('app.color.start_window_background'))
  }

  build() {
    Column() {
      Navigation() {
        Column() {
          Blank()
          Column() {
            Button('Button')
              .type(this.type)
              .stateEffect(this.stateEffect)
              .backgroundColor($r('app.color.brand'))
              .width(this.widthValue)
              .height(this.heightValue)
              .fontSize(this.sizeValue)
          }

          Blank()

          Column() {
            //tab 1
            Column () {
              SelectCustom({ name: 'type', valuesList: $typeValueArr, itemsList: $typeArr, selectItem: $type })
              Divider()
                .color($r('app.color.line_grey'))
              SwitchCustom({ name: 'stateEffect', isOn: $stateEffect })
            }
            .visibility(this.selectTab === 1 ? Visibility.Visible : Visibility.None)
            
            //tab 2
            Column(){
              SliderCustom({ name: 'width', value: $widthValue, min: 50, max: 180 })
              Divider()
                .color($r('app.color.line_grey'))
              SliderCustom({ name: 'height', value: $heightValue, min: 20, max: 120 })
              Divider()
                .color($r('app.color.line_grey'))
              SliderCustom({ name: 'fontSize', value: $sizeValue, min: 10, max: 40 })
            }
            .visibility(this.selectTab === 2 ? Visibility.Visible : Visibility.None)

          }
          .padding({ left: 12, right: 12 })
          .backgroundColor($r('app.color.start_window_background'))
          .margin({ left: 20, right: 20, top: 16, bottom: 16 })
          .borderRadius(16)

        }
        .height('100%')
        .width('100%')

      }
      .height('100%')
      .width('100%')
      .title(this.pageTitle())
      .hideBackButton(false)

    }
    .height('100%')
    .width('100%')
    .backgroundColor($r('app.color.background_grey'))
  }
}

运行后在previewer预览器进行预览,效果如下:

【江鸟中原】ArkUI组件示例_ci

3.在main下面的pages文件夹下建立TextPage.ets项目

项目代码如下:

import TitleTab from '../../component/title/TitleTab'
import Title from '../../component/title/Title'
import SliderCustom from '../../component/controller/SliderCustom'
import SelectCustom from '../../component/controller/SelectCustom'

@Entry
@Component
struct TextPage {
  @State selectTab: number = 1

  //textAlign
  @State textAlign : TextAlign = TextAlign.Center
  @State textAlignList : TextAlign[] = [
  TextAlign.Center,
  TextAlign.Start,
  TextAlign.End
  ]
  @State textAlignValueList : { value: string }[] = [
    { value: 'Center' },
    { value: 'Start' },
    { value: 'End' }
  ]

  //maxLines
  @State maxLines : number = 1

  //textOverflow
  @State textOverflow :TextOverflow = TextOverflow.None
  @State textOverflowList :TextOverflow[] = [
  TextOverflow.None,
  TextOverflow.Clip,
  TextOverflow.Ellipsis,
  ]
  @State textOverflowValueList: { value: string }[] = [
    { value: 'None' },
    { value: 'Clip' },
    { value: 'Ellipsis' }
  ]


  //type
  @State type: TextDecorationType = TextDecorationType.Underline
  @State typeList: TextDecorationType[] = [
  TextDecorationType.Underline,
  TextDecorationType.Overline,
  TextDecorationType.LineThrough,
  TextDecorationType.None
  ]
  @State typeValueList: { value: string }[] = [
    { value: 'Underline' },
    { value: 'Overline' },
    { value: 'LineThrough' },
    { value: 'None' }
  ]

  //color
  @State color: Color = Color.Blue
  @State colorList: Color[] = [
  Color.Blue,
  Color.Black,
  Color.Brown,
  Color.Green,
  Color.Orange,
  Color.Grey
  ]
  @State colorValueList: { value: string }[] = [
    { value: 'Blue' },
    { value: 'Black' },
    { value: 'Brown' },
    { value: 'Green' },
    { value: 'Orange' },
    { value: 'Grey' }
  ]

  //baselineOffset
  @State baselineOffset : number = 0

  //letterSpacing
  @State letterSpacing: number = 5

  //textCase
  @State textCase: TextCase = TextCase.Normal
  @State textCaseList: TextCase[] = [
  TextCase.Normal,
  TextCase.LowerCase,
  TextCase.UpperCase,
  ]
  @State textCaseValueList: { value: string }[] = [
    { value: 'Normal' },
    { value: 'LowerCase' },
    { value: 'UpperCase' }
  ]

  //fontSize
  @State fontSize: number = 20

  //width
  @State widthValue: number = 300

  @Builder pageTitle() {
    Column() {
      Title({ pageTitle: 'Text 文本' })
      TitleTab({ selectTab: $selectTab, interface: false, property: true, common: true })
    }
    .width('100%')
    .backgroundColor($r('app.color.start_window_background'))
  }

  build() {
    Column() {
      Navigation() {
        Column() {
          Blank()
          Column() {
            Text('This is text demonstration')
              .textAlign(this.textAlign)
              .textOverflow({overflow:this.textOverflow})
              .decoration({type:this.type,color:this.color})
              .baselineOffset(this.baselineOffset)
              .letterSpacing(this.letterSpacing)
              .textCase(this.textCase)
              .fontSize(this.fontSize)
              .width(this.widthValue)
              .maxLines(this.maxLines)
          }

          Blank()
          Column() {

            // tab 1
            Column() {
              SelectCustom({
                name: 'textAlign',
                selectItem: $textAlign,
                itemsList: $textAlignList,
                valuesList: $textAlignValueList
              })
              Divider().color($r('app.color.line_grey'))
              SelectCustom({
                name: 'textOverflow',
                selectItem: $textOverflow,
                itemsList: $textOverflowList,
                valuesList: $textOverflowValueList
              })
              Divider().color($r('app.color.line_grey'))
              SliderCustom({name:'maxLines',value:$maxLines,min:1,max:3})
              Divider().color($r('app.color.line_grey'))
              SelectCustom({
                name: 'decoration-type',
                selectItem: $type,
                itemsList: $typeList,
                valuesList: $typeValueList
              })
              Divider().color($r('app.color.line_grey'))
              SelectCustom({
                name: 'decoration-color',
                selectItem: $color,
                itemsList: $colorList,
                valuesList: $colorValueList
              })
              Divider().color($r('app.color.line_grey'))
              SliderCustom({name:'baselineOffset',value:$baselineOffset,min:-20,max:20})
              Divider().color($r('app.color.line_grey'))
              SliderCustom({ name: 'letterSpacing', value: $letterSpacing, min: -10, max: 20 })
              Divider().color($r('app.color.line_grey'))
              SelectCustom({
                name: 'textCase',
                selectItem: $textCase,
                itemsList: $textCaseList,
                valuesList: $textCaseValueList
              })

            }
            .visibility(this.selectTab === 1 ? Visibility.Visible : Visibility.None)

            // tab 2
            Column() {
              SliderCustom({ name: 'fontSize', value: $fontSize, min: 10, max: 40 })
              Divider().color($r('app.color.line_grey'))
              SliderCustom({ value: $widthValue, name: 'width', min: 200, max: 350 })
            }
            .visibility(this.selectTab === 2 ? Visibility.Visible : Visibility.None)

          }
          .padding({ left: 12, right: 12 })
          .backgroundColor($r('app.color.start_window_background'))
          .margin({ left: 20, right: 20, top: 16, bottom: 16 })
          .borderRadius(16)

        }
        .height('100%')
        .width('100%')

      }
      .height('100%')
      .width('100%')
      .title(this.pageTitle())
      .hideBackButton(false)

    }
    .height('100%')
    .width('100%')
    .backgroundColor($r('app.color.background_grey'))
  }
}

运行结果如下:

【江鸟中原】ArkUI组件示例_ci_02

可以通过修改代码实现文本内容的修改。

总结:通过鸿蒙课的学习,我学会了要勇于创新,不能故步自封。只有开发出属于自己的东西才能走的更久,走的更远。

标签:江鸟,name,..,示例,color,app,value,State,ArkUI
From: https://blog.51cto.com/u_16460507/8945552

相关文章

  • 模块描述文件示例
    @[TOC]Jar包的基本概念首先,让我们从JAR包的基本概念开始。JAR,全称JavaArchive,是Java的一种压缩文件格式。它主要用于打包、分发Java类和相关资源,包括Java类文件、资源文件、配置文件以及其他Java应用程序相关文件。与直接编译和运行Java源代码不同,使用JAR包可以更方便地进行应用程......
  • 【江鸟中原】————简单小游戏
    一、引言 经过一段实践学习之后,我开始运用学习过的知识,自己实践创作了一个鸿蒙小型游戏。二、游戏介绍 我所创作的是一个贪吃蛇的小游戏,这个游戏主要思路是在一个1010方格上随机出现一个格子,当贪吃蛇的头出现在格子上时,则贪吃蛇整体长度加1。当贪吃蛇的头部在1010方格之外时,则......
  • Halo2简单应用-斐波那契示例
    电路设计Halo2是基于PLONK算法的零知识证明框架,使用Rust语言。在Halo2中要证明你掌握斐波那契数列,例如Fib(10)=55。则需要将你的每一步计算过程(秘密的)罗列出来。并由程序(电路)来进行验证,生成证明。在PLONK算法里,我们使用表格来进行计算跟踪,例如:abr112123......
  • libevent http-server示例
    wgethttps://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gztarxvzflibevent-2.1.12-stable.tar.gz-C.cdlibevent-2.1.12-stablemkdircmake-build-debugcdcmake-build-debugcmake../-DCMAKE_BUILD_TYPE......
  • CH582,CH583,CH32V208等IC低功耗蓝牙系列2.4G例程RF_PHY/RF_PHY_Hop配对示例
    RF_PHY和RF_PHY_Hop两个例程均可以采用这种思路,甚至可以组合使用,比如RF_PHY用来配对,RF_PHY_Hop用来数据通讯,思路简介:该例程只要收发双方的地址,跳频频道等基础配置项一致即可进行无线通讯,因此可以衍生出其中一种较简单的配对思路,即:1、初始化代码中使用默认地址,例如0x71764129,这样......
  • kaldi lesson教程示例(转载)
    转自:https://blog.csdn.net/q_xiami123/article/details/117019177?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170312043616800188564167%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170312043616800188564167&biz_......
  • 【Spring教程21】Spring框架实战:Spring事务简介、AOP事务管理、代码示例全面详解
    欢迎大家回到《Java教程之Spring30天快速入门》,本教程所有示例均基于Maven实现,如果您对Maven还很陌生,请移步本人的博文《如何在windows11下安装Maven并配置以及IDEA配置Maven环境》,本文的上一篇为《AOP(面对切面编程)知识总结》1相关概念介绍事务作用:在数据层保障一系列的数据库操......
  • es使用示例
    记录是否存在res=es.exists(index="ncbi_gene",id=_id)插入记录es_res=self.es.index(index="ncbi_gene",id=my_data['GeneID'],body=my_data)ifes_res['result']in['created','updated']:logging.......
  • 正则表达式相关。示例:包含a和b,包含a不包含b
    普通字符普通字符包括没有显式指定为元字符的所有可打印和不可打印字符。这包括所有大写和小写字母、所有数字、所有标点符号和一些其他符号。非打印字符非打印字符也可以是正则表达式的组成部分。下表列出了表示非打印字符的转义序列:字符描述\cx匹配由x指明的控制字符。......
  • Keepalived+Nginx+Tomcat配置高可用负载均衡系统示例
    前言目前生产环境的配置越来越多的使用云服务了,同时负载均衡也基本转向了云厂商提供的服务,但对于绝大多数应用来说,自建集群可能在费用上要更便宜一些,这篇文章也是之前整理的,再次新瓶装旧酒分享给各位。此示例演示在不使用docker的情况下配置负载均衡,内容keepalived+nginx+tomcat......