11.HarmonyOS鸿蒙app_page的显示跳转方法

11.HarmonyOS鸿蒙app_page的显示跳转方法,text文本触发点击事件

使用Intent和Operation对象

创建新项目后,再创建secondPageAbility

ability_main.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">

    <Text
        ohos:id="$+id:text_main"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:background_element="$graphic:background_ability_main"
        ohos:layout_alignment="horizontal_center"
        ohos:text="$string:main_title1"
        ohos:text_size="40vp"
        />

</DirectionalLayout>

Secondability_main.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">

    <Text
        ohos:id="$+id:text_second"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:background_element="#9090FF"
        ohos:layout_alignment="horizontal_center"
        ohos:text="$string:second_title"
        ohos:text_size="40vp"
        />

</DirectionalLayout>

MainAbilitySlice.java

复制代码
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.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Text text = (Text) findComponentById(ResourceTable.Id_text_main);
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent _intent = new Intent();
                //创建Operation对象
                Operation operation = new Intent.OperationBuilder().withDeviceId("")
                        .withBundleName("com.example.myapplication")
                        .withAbilityName("com.example.myapplication.SecondPageAbility")
                        .build();
                _intent.setOperation(operation);
                //启动ability
                startAbility(_intent);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

SecondPageAbilitySlice.java

复制代码
//结束当前的Ability
terminateAbility();
复制代码
package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class SecondPageAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_Secondability_main);
        Text text = (Text) findComponentById(ResourceTable.Id_text_second);
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                //结束当前的Ability
                terminateAbility();
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

string的配置

相关推荐
桃子酱紫君7 小时前
华为配置篇-ISIS基础实验
华为
泡泡大魔王8 小时前
鸿蒙ArkTS开发:微信/系统来电通话监听功能实现
华为·harmonyos
黑臂麒麟8 小时前
harmonyOS基础- 快速弄懂HarmonyOS ArkTs基础组件、布局容器(前端视角篇)
harmonyos·arkui
Yeats_Liao8 小时前
华为开源自研AI框架昇思MindSpore应用案例:基于MindSpore框架实现PWCNet光流估计
人工智能·华为
The旺10 小时前
《HarmonyOS Next开发进阶:打造功能完备的Todo应用华章》
harmonyos
fatiaozhang952713 小时前
晶晨S905L3A(B)-安卓9.0-开启ADB和ROOT-支持IPTV6-支持外置游戏系统-支持多种无线芯片-支持救砖-完美通刷线刷固件包
android·游戏·adb·华为·电视盒子·机顶盒rom·魔百盒固件
用户5457483417713 小时前
Harmonyos5应用开发实战——地图组件集成与定位功能实现(part1)
harmonyos
用户5457483417713 小时前
Harmonyos5应用开发实战——订单页面开发(part2)
harmonyos
用户5457483417713 小时前
Harmonyos5应用开发实战——地图组件集成与定位功能实现(part2)
harmonyos
用户5457483417714 小时前
HarmonyOS Next应用开发实战——登录页面实现(part1)
harmonyos