HarmonyOS 点击事件的实现
生活随笔
收集整理的這篇文章主要介紹了
HarmonyOS 点击事件的实现
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
HarmonyOS 點(diǎn)擊事件使用的方法
HarmonyOS 點(diǎn)擊事件 使用 setClickedListener
編譯器提醒換是很不錯(cuò)的
點(diǎn)擊事件具體的實(shí)現(xiàn)
xml 寫(xiě)一個(gè)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("點(diǎn)擊了").show();}});}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}
點(diǎn)擊會(huì)有個(gè)Toast
總結(jié)
以上是生活随笔為你收集整理的HarmonyOS 点击事件的实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: adb: unable to conne
- 下一篇: 驯开头的成语有哪些啊?