網站首頁 編程語言 正文
布局
代碼
package com.example.helloworld.slice;
import com.example.helloworld.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;
import ohos.multimodalinput.event.TouchEvent;
public class MainAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
Button btn1 = findComponentById(ResourceTable.Id_btn1);
Button btn2 = findComponentById(ResourceTable.Id_btn2);
btn1.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
Intent intent = new Intent();
//withDeviceId 跳轉到那個設備上,如果傳遞一個沒有內容的字符串 標識跳轉本機
//withBundleName 跳轉那個應用上面
//withAbilityName 要跳轉的頁面
Operation build = new Intent.OperationBuilder()
.withDeviceId("")
.withBundleName("com.example.helloworld")
.withAbilityName(".SecondAbility")
.build();
intent.setOperation(build);
startAbility(intent);
}
});
btn1.setDoubleClickedListener(new Component.DoubleClickedListener() {
@Override
public void onDoubleClick(Component component) {
btn1.setText("我被雙擊了");
}
});
btn1.setLongClickedListener(new Component.LongClickedListener() {
@Override
public void onLongClicked(Component component) {
btn1.setText("我被長按了");
}
});
btn2.setTouchEventListener(new Component.TouchEventListener() {
@Override
public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
int action = touchEvent.getAction();
switch (action){
//按下
case TouchEvent.PRIMARY_POINT_DOWN:
btn2.setText("按下");
break;
//彈起
case TouchEvent.PRIMARY_POINT_UP:
btn2.setText("彈起");
break;
//滑動
case TouchEvent.POINT_MOVE:
btn2.setText("滑動");
break;
}
return true;
}
});
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
這里記得修改為true
否則可能會只有按下事件?
?
?
原文鏈接:https://blog.csdn.net/mp624183768/article/details/124399121
相關推薦
- 2022-06-14 Python?torch.fft.rfft()函數用法示例代碼_python
- 2022-10-17 Python?Django源碼運行過程解析_python
- 2022-09-01 Nginx?部署的虛擬主機使用?Let's?Encrypt?加密?https的方法_nginx
- 2022-11-25 Go實現快速生成固定長度的隨機字符串_Golang
- 2022-10-24 Django使用Redis進行緩存詳細步驟_Redis
- 2022-10-22 SQLMAP插件tamper模塊簡介_MsSql
- 2023-01-21 VmWare安裝Centos后配置Net網絡SSH鏈接問題及解決_VMware
- 2022-06-13 Python+Matplotlib繪制雙y軸圖像的示例代碼_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支