当前位置:   article > 正文

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

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);
        });

  1. package com.example.myapplication3.slice;
  2. import com.example.myapplication3.ResourceTable;
  3. import com.example.myapplication3.SecondPageAbility;
  4. import ohos.aafwk.ability.AbilitySlice;
  5. import ohos.aafwk.content.Intent;
  6. import ohos.aafwk.content.Operation;
  7. import ohos.agp.components.Button;
  8. import ohos.agp.components.Component;
  9. import ohos.agp.components.Text;
  10. import ohos.utils.IntentConstants;
  11. public class MainAbilitySlice extends AbilitySlice {
  12. @Override
  13. public void onStart(Intent intent) {
  14. super.onStart(intent);
  15. super.setUIContent(ResourceTable.Layout_ability_main);
  16. Text text = (Text) findComponentById(ResourceTable.Id_text_main);
  17. Button btn = (Button) findComponentById(ResourceTable.Id_btn_main);
  18. text.setClickedListener(new Component.ClickedListener() {
  19. @Override
  20. public void onClick(Component component) {
  21. Intent _intent = new Intent();
  22. Operation operation = new Intent.OperationBuilder()
  23. .withDeviceId("")
  24. .withBundleName(getBundleName())
  25. .withAbilityName(SecondPageAbility.class.getName())
  26. // .withAction(SecondPageAbility.ACTION_TARGET)
  27. .build();
  28. _intent.setOperation(operation);
  29. // _intent.setAction(SecondPageAbility.ACTION_TARGET);
  30. startAbility(_intent);
  31. }
  32. });
  33. btn.setClickedListener(component -> {
  34. Intent _intent = new Intent();
  35. Operation operation = new Intent.OperationBuilder()
  36. .withBundleName( getBundleName())
  37. .withAction(SecondPageAbility.ACTION_TARGET)
  38. .withAbilityName(SecondPageAbility.class.getName())
  39. .build();
  40. _intent.setOperation(operation);
  41. startAbility(_intent);
  42. });
  43. }
  44. @Override
  45. public void onActive() {
  46. super.onActive();
  47. }
  48. @Override
  49. public void onForeground(Intent intent) {
  50. super.onForeground(intent);
  51. }
  52. }
SecondPageAbility设置actionRoute
  1. package com.example.myapplication3;
  2. import com.example.myapplication3.slice.SecondPageAbilitySlice;
  3. import com.example.myapplication3.slice.TargetAbilitySlice;
  4. import ohos.aafwk.ability.Ability;
  5. import ohos.aafwk.content.Intent;
  6. public class SecondPageAbility extends Ability {
  7. public static final String ACTION_TARGET = "action.intent.target_ability_slice";
  8. public static final String ACTION_Second = "action.intent.second_ability_slice";
  9. @Override
  10. public void onStart(Intent intent) {
  11. super.onStart(intent);
  12. super.setMainRoute(SecondPageAbilitySlice.class.getName());
  13. // super.addActionRoute(ACTION_Second, SecondPageAbilitySlice.class.getName());
  14. super.addActionRoute(ACTION_TARGET, TargetAbilitySlice.class.getName());
  15. // super.addActionRoute("action.intent.target_ability_slice", TargetAbilitySlice.class.getName());
  16. }
  17. }

config.json添加,skills/actions

 capsule_btn_element.xml

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

按钮样式的使用方法:

工程代码:

https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501icon-default.png?t=N7T8https://download.csdn.net/download/txwtech/88658909?spm=1001.2014.3001.5501 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号