HarmonyOSAPP-TimePicker体验与分享 原创

发布于 2021-3-20 12:23
浏览
0收藏

显示效果:

  HarmonyOSAPP-TimePicker体验与分享-开源基础软件社区

上下拖动改变选中的值

  HarmonyOSAPP-TimePicker体验与分享-开源基础软件社区

布局中的代码:

<?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:orientation="vertical">

    <TimePicker
        ohos:id="$+id:time_picker"
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:normal_text_color="#007DFF"
        ohos:normal_text_size="25fp"
        ohos:operated_text_color="#FF9912"
        ohos:shader_color="#00BFFF"/>

</DirectionalLayout>

Slice文件中

package com.example.jltftiyan5.slice;

import com.example.jltftiyan5.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TimePicker;

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

        TimePicker timePicker = (TimePicker) findComponentById(ResourceTable.Id_time_picker);
        int hour = timePicker.getHour();
        int minute = timePicker.getMinute();
        int second = timePicker.getSecond();

        timePicker.setHour(19);
        timePicker.setMinute(18);
        timePicker.setSecond(12);
        timePicker.setTimeChangedListener(new TimePicker.TimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker timePicker, int hour, int minute, int second) {

            }
        });
    }

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

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

完整代码下载地址:

https://gitee.com/jltfcloudcn/jump_to/tree/master/jltf_TimePicker_component

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
标签
收藏
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐