1.日期排版
ohos:shader_color="gray"渐变色
2.代码
// 通过id找到日期哥文本组件
datePicker1=(DatePicker)findComponentById(ResourceTable.Id_datePicker);
text1=(Text)findComponentById(ResourceTable.Id_text1);
// 绑定监听组件
datePicker1.setValueChangedListener(new myDateListneer());
}
// 内部类
public class myDateListneerimplements DatePicker.ValueChangedListener{
@Override
public void onValueChanged(DatePicker datePicker, int i, int i1, int i2) {
if ( datePicker==datePicker1){
text1.setText(i+"年"+i1+"月"+i2+"日");
}
}
}
3.时钟的写法
timePicker = (TimePicker) findComponentById(ResourceTable.Id_timePicker);
text2 = (Text) findComponentById(ResourceTable.Id_text2);
// 绑定监听组件
// 匿名内部类的监听绑定法
timePicker.setTimeChangedListener(new TimePicker.TimeChangedListener() {
@Override
public void onTimeChanged(TimePicker timePicker, int i, int i1, int i2) {
text2.setText(i +"时" + i1 +"分" + i2 +"秒");
}
});
网友评论