網站首頁 編程語言 正文
修改默認Main的布局
match_content 是不是有人想起來了 wrap_content
ui效果如下
新建頁面2
?
?取名
SecondAbility
就好
?修改代碼 我們通過代碼的方式創建布局
package com.example.helloworld.slice;
import com.example.helloworld.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
public class SecondAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
// super.setUIContent(ResourceTable.Layout_ability_second);
//創建布局對象
DirectionalLayout directionalLayout = new DirectionalLayout(this);
Text text = new Text(this);
text.setText("第二個頁面");
text.setTextSize(55);
text.setTextColor(Color.BLUE);
directionalLayout.addComponent(text);
setUIContent(directionalLayout);
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
MainAbilitySlice
修改下
跳轉核心代碼來咯
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;
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);
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);
}
});
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
Very ugly, but useful
?
原文鏈接:https://blog.csdn.net/mp624183768/article/details/124368945
相關推薦
- 2022-09-18 Go實現文件分片上傳_Golang
- 2022-08-15 springboot使用配置文件配置bean屬性產生中文亂碼問題
- 2022-09-28 k8s證書有效期時間修改的方法詳解_云其它
- 2023-01-01 淺析C++中static的一些用法_C 語言
- 2022-08-10 pandas.DataFrame.iloc的具體使用詳解_python
- 2022-02-13 如何寫一個自己的strcpy函數
- 2022-10-17 C#使用WebSocket與網頁實時通信的實現示例_C#教程
- 2022-02-16 Flutter無context頁面跳轉及獲取全局context
- 最近更新
-
- 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同步修改后的遠程分支