新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS實(shí)現(xiàn)頁面跳轉(zhuǎn)
- 打開第一個(gè)頁面的“
MainAbilitySlice.java”文件,重寫onStart()方法添加按鈕的響應(yīng)邏輯,實(shí)現(xiàn)點(diǎn)擊按鈕跳轉(zhuǎn)到下一頁,示例代碼如下:
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;
public class MainAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_main_layout);
Button button = (Button) findComponentById(ResourceTable.Id_button);
if (button != null) {
// 為按鈕設(shè)置點(diǎn)擊回調(diào)
button.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
Intent secondIntent = new Intent();
// 指定待啟動(dòng)FA的bundleName和abilityName
Operation operation = new Intent.OperationBuilder()
.withDeviceId("")
.withBundleName("com.example.myapplication")
.withAbilityName("com.example.myapplication.SecondAbility")
.build();
secondIntent.setOperation(operation);
startAbility(secondIntent); // 通過AbilitySlice的startAbility接口實(shí)現(xiàn)啟動(dòng)另一個(gè)頁面
}
});
}
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了邢臺(tái)縣免費(fèi)建站歡迎大家使用!
- 再次運(yùn)行項(xiàng)目,效果如圖所示:
分享標(biāo)題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS實(shí)現(xiàn)頁面跳轉(zhuǎn)
標(biāo)題路徑:http://www.5511xx.com/article/djesise.html


咨詢
建站咨詢
