14.鸿蒙HarmonyOS App(JAVA)时钟组件计时器倒计时单选按钮复选框开关switch与开关按钮ToggleButton图像组件示范

本文主要是介绍14.鸿蒙HarmonyOS App(JAVA)时钟组件计时器倒计时单选按钮复选框开关switch与开关按钮ToggleButton图像组件示范,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

鸿蒙HarmonyOS App(JAVA)

时钟组件

计时器

倒计时

单选按钮

复选框

开关switch

开关按钮ToggleButton

图像组件

ability_main.xml

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:alignment="center"ohos:background_element="#FC708FF5"ohos:orientation="vertical"><Textohos:id="$+id:text_helloworld"ohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="$string:mainability_HelloWorld"ohos:text_size="30vp"/><Clockohos:id="$+id:clock"ohos:height="match_content"ohos:width="380vp"ohos:background_element="#FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text_size="30vp"/><Textohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="计时器组件(TickTimer)"ohos:text_size="30vp"/><!--正计时 --><TickTimerohos:id="$+id:ticktimer"ohos:height="match_content"ohos:width="380vp"ohos:background_element="#FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text_size="30vp"/><!--倒计时 --><TickTimerohos:id="$+id:ticktimer_countdown"ohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:count_down="true"ohos:text_size="30vp"/><Textohos:height="match_content"ohos:width="380vp"ohos:background_element="#FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text="单选按钮:"ohos:text_size="30vp"/><RadioContainerohos:id="$+id:radio_container"ohos:height="match_content"ohos:width="match_content"ohos:alignment="center"ohos:background_element="#FC708FF5"ohos:layout_alignment="horizontal_center"><RadioButtonohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="第一个选项"ohos:text_size="30vp" /><RadioButtonohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="第二个选项"ohos:text_size="30vp" /><RadioButtonohos:height="match_content"ohos:width="380vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="第三个选项"ohos:text_size="30vp" /></RadioContainer><!--复选框checkbox --><!--开关switch --><!--开关按钮ToggleButton --><Checkboxohos:id="$+id:check_box1"ohos:height="match_content"ohos:width="150vp"ohos:background_element="FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text="复选框1"ohos:text_size="30vp" /><Switchohos:id="$+id:switch1"ohos:height="match_content"ohos:width="100vp"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="复选框1"ohos:text_size="30vp" /><ToggleButtonohos:id="$+id:toggle_btn1"ohos:height="match_content"ohos:width="100vp"ohos:background_element="FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text_state_on="打开"ohos:text_state_off="关闭"ohos:text_size="30vp" /><Textohos:height="match_content"ohos:width="380vp"ohos:background_element="#FF80EF66"ohos:layout_alignment="horizontal_center"ohos:text="图像组件:"ohos:text_size="30vp"/><Imageohos:height="100vp"ohos:width="100vp"ohos:background_element="gray"ohos:layout_alignment="left"ohos:image_src="$media:lucky_grass"ohos:scale_mode="inside"/><!-- ohos:image_src="$graphic:ic_back" --></DirectionalLayout>

 MainAbilitySlice.java

package com.example.myapplication.slice;import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;public class MainAbilitySlice extends AbilitySlice {@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);//常规计时TickTimer tickTimer =(TickTimer) findComponentById(ResourceTable.Id_ticktimer);tickTimer.start();//倒计时TickTimer tickTimer_countdown =(TickTimer) findComponentById(ResourceTable.Id_ticktimer_countdown);tickTimer_countdown.setBaseTime((System.currentTimeMillis()+30*1000));tickTimer_countdown.setFormat("倒计时:ss秒");tickTimer_countdown.start();Clock clock = (Clock)  findComponentById(ResourceTable.Id_clock);clock.setFormatIn24HourMode("yyyy-MM-dd HH:mm:ss");RadioContainer radioContainer=(RadioContainer) findComponentById(ResourceTable.Id_radio_container);radioContainer.setMarkChangedListener(new RadioContainer.CheckedStateChangedListener() {@Overridepublic void onCheckedChanged(RadioContainer radioContainer, int i) {new ToastDialog(getContext()).setText("选择了第"+(i+1)+"项").setAlignment(LayoutAlignment.CENTER).show();}});ToggleButton toggleButton = (ToggleButton) findComponentById(ResourceTable.Id_toggle_btn1);toggleButton.setClickedListener(new Component.ClickedListener() {@Overridepublic void onClick(Component component) {new ToastDialog(getContext()).setText("点击了:"+toggleButton.getText()).show();}});}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}

图像组件的图像SGV文件转xml方法:

找到svg to xml

 

导入后:

图片使用方法:

工程代码:

待更新。。。

这篇关于14.鸿蒙HarmonyOS App(JAVA)时钟组件计时器倒计时单选按钮复选框开关switch与开关按钮ToggleButton图像组件示范的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/611563

相关文章

SpringBoot条件注解核心作用与使用场景详解

《SpringBoot条件注解核心作用与使用场景详解》SpringBoot的条件注解为开发者提供了强大的动态配置能力,理解其原理和适用场景是构建灵活、可扩展应用的关键,本文将系统梳理所有常用的条件注... 目录引言一、条件注解的核心机制二、SpringBoot内置条件注解详解1、@ConditionalOn

OpenCV图像形态学的实现

《OpenCV图像形态学的实现》本文主要介绍了OpenCV图像形态学的实现,包括腐蚀、膨胀、开运算、闭运算、梯度运算、顶帽运算和黑帽运算,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起... 目录一、图像形态学简介二、腐蚀(Erosion)1. 原理2. OpenCV 实现三、膨胀China编程(

通过Spring层面进行事务回滚的实现

《通过Spring层面进行事务回滚的实现》本文主要介绍了通过Spring层面进行事务回滚的实现,包括声明式事务和编程式事务,具有一定的参考价值,感兴趣的可以了解一下... 目录声明式事务回滚:1. 基础注解配置2. 指定回滚异常类型3. ​不回滚特殊场景编程式事务回滚:1. ​使用 TransactionT

Spring LDAP目录服务的使用示例

《SpringLDAP目录服务的使用示例》本文主要介绍了SpringLDAP目录服务的使用示例... 目录引言一、Spring LDAP基础二、LdapTemplate详解三、LDAP对象映射四、基本LDAP操作4.1 查询操作4.2 添加操作4.3 修改操作4.4 删除操作五、认证与授权六、高级特性与最佳

Spring Shell 命令行实现交互式Shell应用开发

《SpringShell命令行实现交互式Shell应用开发》本文主要介绍了SpringShell命令行实现交互式Shell应用开发,能够帮助开发者快速构建功能丰富的命令行应用程序,具有一定的参考价... 目录引言一、Spring Shell概述二、创建命令类三、命令参数处理四、命令分组与帮助系统五、自定义S

SpringQuartz定时任务核心组件JobDetail与Trigger配置

《SpringQuartz定时任务核心组件JobDetail与Trigger配置》Spring框架与Quartz调度器的集成提供了强大而灵活的定时任务解决方案,本文主要介绍了SpringQuartz定... 目录引言一、Spring Quartz基础架构1.1 核心组件概述1.2 Spring集成优势二、J

SpringSecurity JWT基于令牌的无状态认证实现

《SpringSecurityJWT基于令牌的无状态认证实现》SpringSecurity中实现基于JWT的无状态认证是一种常见的做法,本文就来介绍一下SpringSecurityJWT基于令牌的无... 目录引言一、JWT基本原理与结构二、Spring Security JWT依赖配置三、JWT令牌生成与

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

如何配置Spring Boot中的Jackson序列化

《如何配置SpringBoot中的Jackson序列化》在开发基于SpringBoot的应用程序时,Jackson是默认的JSON序列化和反序列化工具,本文将详细介绍如何在SpringBoot中配置... 目录配置Spring Boot中的Jackson序列化1. 为什么需要自定义Jackson配置?2.

Java中使用Hutool进行AES加密解密的方法举例

《Java中使用Hutool进行AES加密解密的方法举例》AES是一种对称加密,所谓对称加密就是加密与解密使用的秘钥是一个,下面:本文主要介绍Java中使用Hutool进行AES加密解密的相关资料... 目录前言一、Hutool简介与引入1.1 Hutool简介1.2 引入Hutool二、AES加密解密基础