Salto de página de HarmonyOS

Modificar el diseño del principal predeterminado

<?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_helloworld"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:background_element="$graphic:background_ability_main"
        ohos:layout_alignment="horizontal_center"
        ohos:text="第一个页面"
        ohos:text_size="40vp"
        />

    <Button
        ohos:id="$+id:btn1"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:background_element="red"
        ohos:text="跳转下一个页面"
        ohos:text_size="40fp"/>

</DirectionalLayout>
¿match_content recuerda wrap_content?

El efecto ui es el siguiente

Pagina nueva 2

 

 tomar un nombre

Segunda Habilidad

muy bien

 Modificar el código Creamos el diseño por código

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

modificar

Saltar al código central

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

Muy feo, pero útil.

 

Supongo que te gusta

Origin blog.csdn.net/mp624183768/article/details/124368945
Recomendado
Clasificación