HarmonyOS-实现点赞demo-JAVA

发布于 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 19次下载
yanshi.rar 1.07M 0次下载
1
收藏
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐