日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

HarmonyOS 点击事件的实现

發布時間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 点击事件的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。