12.鸿蒙HarmonyOS App(JAVA) page的隐式跳转

跳转到指定Page的指定AbilitySlice

复制代码
MainAbilitySlice按钮触发事件:

btn.setClickedListener(component -> {

Intent _intent = new Intent();

Operation operation = new Intent.OperationBuilder()

.withBundleName( getBundleName())

.withAction(SecondPageAbility.ACTION_TARGET)

.withAbilityName(SecondPageAbility.class.getName())

.build();

_intent.setOperation(operation);

startAbility(_intent);

});

package com.example.myapplication3.slice;

import com.example.myapplication3.ResourceTable;
import com.example.myapplication3.SecondPageAbility;
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.components.Text;
import ohos.utils.IntentConstants;

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);
        Button btn = (Button) findComponentById(ResourceTable.Id_btn_main);
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent _intent = new Intent();

                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")

                        .withBundleName(getBundleName())

                        .withAbilityName(SecondPageAbility.class.getName())
                      //  .withAction(SecondPageAbility.ACTION_TARGET)
                        .build();
                _intent.setOperation(operation);
             //   _intent.setAction(SecondPageAbility.ACTION_TARGET);

                startAbility(_intent);
            }
        });
        btn.setClickedListener(component -> {
            Intent _intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName( getBundleName())
                    .withAction(SecondPageAbility.ACTION_TARGET)
                    .withAbilityName(SecondPageAbility.class.getName())

                    .build();
            _intent.setOperation(operation);


            startAbility(_intent);
        });
    }

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

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
复制代码
SecondPageAbility设置actionRoute
package com.example.myapplication3;

import com.example.myapplication3.slice.SecondPageAbilitySlice;
import com.example.myapplication3.slice.TargetAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;

public class SecondPageAbility extends Ability {
    public static final String ACTION_TARGET = "action.intent.target_ability_slice";
    public static final String ACTION_Second = "action.intent.second_ability_slice";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(SecondPageAbilitySlice.class.getName());
       // super.addActionRoute(ACTION_Second, SecondPageAbilitySlice.class.getName());
        super.addActionRoute(ACTION_TARGET, TargetAbilitySlice.class.getName());
       // super.addActionRoute("action.intent.target_ability_slice", TargetAbilitySlice.class.getName());

    }
}

config.json添加,skills/actions

capsule_btn_element.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"
       ohos:shape="rectangle">
    <corners
        ohos:radius="100"/>
    <solid
        ohos:color="#007CFD"/>
</shape>

按钮样式的使用方法:

工程代码:

https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501

相关推荐
SuperHeroWu730 分钟前
【HarmonyOS】键盘遮挡输入框UI布局处理
华为·harmonyos·压缩·keyboard·键盘遮挡·抬起
sanzk5 小时前
华为鸿蒙应用开发
华为·harmonyos
SoraLuna9 小时前
「Mac畅玩鸿蒙与硬件28」UI互动应用篇5 - 滑动选择器实现
macos·ui·harmonyos
ClkLog-开源埋点用户分析10 小时前
ClkLog企业版(CDP)预售开启,更有鸿蒙SDK前来助力
华为·开源·开源软件·harmonyos
mg66810 小时前
鸿蒙系统的优势 开发 环境搭建 开发小示例
华为·harmonyos
模拟IC攻城狮11 小时前
华为海思招聘-芯片与器件设计工程师-模拟芯片方向- 机试题-真题套题题目——共8套(每套四十题)
嵌入式硬件·华为·硬件架构·芯片
lqj_本人11 小时前
鸿蒙next选择 Flutter 开发跨平台应用的原因
flutter·华为·harmonyos
lqj_本人11 小时前
使用 Flutter 绘制一个棋盘
harmonyos
TangKenny11 小时前
计算网络信号
java·算法·华为
23zhgjx-NanKon12 小时前
华为eNSP:QinQ
网络·安全·华为