網站首頁 編程語言 正文
修改默認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-08-25 消息交換模式RabbitMQ簡介_其它綜合
- 2022-02-25 C++的靜態成員變量和靜態成員函數詳解_C 語言
- 2022-01-03 yarn版本過低導致的報錯
- 2022-10-09 Python?pygame項目實戰監聽退出事件_python
- 2022-12-13 一文詳解Python加解壓文件gzip庫的操作_python
- 2022-11-10 android時間選擇控件之TimePickerView使用方法詳解_Android
- 2022-06-28 ASP.NET?WebAPI導出CSV_實用技巧
- 2022-06-27 nginx中配置使用proxy?protocol協議的全過程_nginx
- 最近更新
-
- 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同步修改后的遠程分支