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