HarmonyOS 点击事件的实现
HarmonyOS 点击事件使用的方法
HarmonyOS 点击事件 使用 setClickedListener
编译器提醒换是很不错的
点击事件具体的实现
xml 写一个button 如下
<?xml version="1.0" encoding="utf-8"?>
<DependentLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:background_element="#3387CEFA"><Buttonohos:id="$+id:button1"ohos:height="50vp"ohos:width="100vp"ohos:center_in_parent="true"ohos:background_element="#00FFFF"ohos:text="Java"ohos:text_alignment="center"ohos:text_size="20fp"/></DependentLayout>
java 代码
package com.example.myapplication.slice;import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.OnClickListener;
import ohos.aafwk.content.Intent;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;import java.util.logging.Logger;public class MainAbilitySlice extends AbilitySlice {private Button button1;@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);button1 = (Button) findComponentById(ResourceTable.Id_button1);button1.setClickedListener(new Component.ClickedListener() {@Overridepublic void onClick(Component component) {new ToastDialog(getContext()).setText("点击了").show();}});}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}
点击会有个Toast
HarmonyOS 点击事件的实现相关推荐
- (3.5)HarmonyOS鸿蒙多按钮点击事件
多按钮的点击事件其实与只有一个是类似的,只不过要在调用 onClick()时进行判断,判断获取到的component是谁即可. package com.example.yeman.slice;impo ...
- Android 监听多个Spinner 的点击事件
同一个界面有多个Spinner 点击事件的时候 只有一个onItemSelected 我们可以使用 给不同的点击事件添加Tag 来区分 具体的做法如下: 下面的代码主要体现在添加spinner.set ...
- Android DataBinding 入门了解 到实现一个buttton的点击事件
为了更好的学习mvvm 这里从新学习databinding.... 1 首先在app下面的Gradle 里面的android 里面 添加 dataBinding {enabled = true} 如下 ...
- RecylerView为item添加点击事件
RecyclerView侧重的是布局的灵活性,虽说可以替代ListView但是连基本的点击事件都没有,这篇文章就来详细讲解如何为RecyclerView的item添加点击事件. 1 原理: 为Recy ...
- 给View 添加手势,点击无反应 如何给View添加点击事件,手势方法
项目中有很多地方需要添加点击事件,重复代码很多,所以做了一个UIView的分类,专门做点击事件使用. 项目地址:UIView-Tap 代码很简单,主要有一点就是注意分类不能直接添加属性,需要用到运行时 ...
- iostext添加点击事件_iOS给UILabel添加点击事件
前言:笔者最近需要实现给UILabel中的链接添加点击事件的功能.使用so.com查了下,发现TTTAttributedLabel的封装程度比较好.整理了TTTAttributedLabel的基本使用 ...
- android 点击事件消费,Android View事件分发和消费源码简单理解
Android View事件分发和消费源码简单理解 前言: 开发过程中觉得View事件这块是特别烧脑的,看了好久,才自认为看明白.中间上网查了下singwhatiwanna粉丝的读书笔记,有种茅塞顿开 ...
- 【Ant Design Pro 四】react 点击事件传参
简单的绑定点击事件传参: 点击事件 function myClick(){console.log('点击')}return (<Button onClick={myClick}>点击< ...
- React 组件绑定点击事件,并且传参完整Demo
微信小程序开发交流qq群 173683895 承接微信小程序开发.扫码加微信. 1.传数组下标给点击事件Demo: const A = 65 // ASCII character codec ...
最新文章
- 获取两个数百分比的值
- Py之av:av库的简介、安装、使用方法之详细攻略
- android 程序退出广播,android 利用广播实现程序的强制退出
- HTML 文件在PC移动端完美自适应布局的技巧
- 分享一套高级Java笔试题(实拍高清图)
- Linux下文件的多进程拷贝
- 计算机基础知识ip地址,计算机基础知识练习题
- R中‘ts‘ object must have one or more observations
- Python环境安装脚本,拷贝环境脚本,命令迁移模块(pip freeze requirements.txt)
- 解决Failed to load the JNI shared library xxx/xxx/jvm.dll 错误
- 用批处理替换文件中的内容
- VMware资源集合,分享一波
- servlet-mapping_浅谈servletmapping的机制(二)
- EPC901安装XP
- JAVA UrlRewrite 使用教程与注意点,JAVA 实现伪静态,URLRewrite实现url地址伪静态化,springboot中url地址重写(urlwrite),jeesite4伪静态
- Origin画甘特图-II
- Dfinity(ICP)介绍-1
- 【实用的微缩版 初级开发面试题】
- ASEMI快恢复模块MUR20060CT的发展前景
- 使用Java蓝牙无线通讯技术API