HarmonyOS-实现点赞demo-JAVA

HUAWEI_Engineer
发布于 2021-10-28 17:47
浏览
0收藏

1.ability_main.xml

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    ohos:id="$+id:dl"
    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="$string:mainability_HelloWorld"-->
<!--        ohos:text_size="40vp"-->
<!--        />-->
    <Image
        ohos:id="$+id:img"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:image_src="$media:icon1"
        />


</DirectionalLayout>

2.MainAbilitySlice

public class MainAbilitySlice extends AbilitySlice implements Component.DoubleClickedListener {
    Image image;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        image = (Image)findComponentById(ResourceTable.Id_img);

        //   获取DirectionalLayout对象
        DirectionalLayout directionalLayout = (DirectionalLayout)findComponentById(ResourceTable.Id_dl);

        directionalLayout.setDoubleClickedListener(this);
    }

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

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

    boolean flag = false;
    @Override
    public void onDoubleClick(Component component) {


        if (flag){
            image.setImageAndDecodeBounds(ResourceTable.Media_icon1);
            flag = false;
        }else{
            image.setImageAndDecodeBounds(ResourceTable.Media_icon2);
            flag = true;
        }

    }
}

3.效果图
HarmonyOS-实现点赞demo-JAVA-鸿蒙开发者社区

4.双击后
HarmonyOS-实现点赞demo-JAVA-鸿蒙开发者社区

标签
HarmonyOS.rar 1.25M 38次下载
yanshi.rar 1.07M 7次下载
1
收藏
回复
举报
回复
    相关推荐