Android uses third-party libraries to implement date selectors

This article mainly introduces how to use the third-party library to realize the bottom date selector roller effect, which is similar to the IOS date effect. Only one display effect is recorded, which is commonly used in the project. For other effects and user-defined extensions, you can refer to the original text and learn by yourself.

Original GitHub address

Effect drawing reference:

usage method:

1. As add dependency: compile 'com. Contrarywind: Android pickerview: 3.2.6'

2. Add the following code to the activity:

TimePickerView pvTime = new TimePickerView.Builder(this,new TimePickerView.OnTimeSelectListener() {
   @Override
   public void onTimeSelect(Date date,View v) {
    btn_date.setText(getTime(date));
   }
  })
    .setType(new boolean[]{true,true,false,false})// 认全部显示
    .setCancelText("取消")//取消按钮文字
    .setSubmitText("确定")//确认按钮文字
//    .setContentSize(18)//滚轮文字大小
//    .setTitleSize(20)//标题文字大小
//    //.setTitleText("Title")//标题文字
//    .setOutSideCancelable(true)//点击屏幕,点在控件外部范围时,是否取消显示
//    .isCyclic(true)//是否循环滚动
//    //.setTitleColor(Color.BLACK)//标题文字颜色
//    .setSubmitColor(Color.BLUE)//确定按钮文字颜色
//    .setCancelColor(Color.BLUE)//取消按钮文字颜色
//    //.setTitleBgColor(0xFF666666)//标题背景颜色 Night mode
//    .setBgColor(0xFF333333)//滚轮背景颜色 Night mode
////    .setDate(selectedDate)// 如果不设置的话,认是系统时间*/
////    .setRangDate(startDate,endDate)//起始终止年月日设定
//    //.setLabel("年","月","日","时","分","秒")//认设置为年月日时分秒
    .isCenterLabel(false) //是否只显示中间选中项的label文字,false则每项item全部都带有label。
    //.isDialog(true)//是否显示为对话框样式
    .build();

  pvTime.show();

3. Run as to see the effect. It's so simple.

A good memory is not as good as a bad pen. The above is just a simple personal record. It is only suitable for novices. It is convenient for themselves and others. If you are lucky to help you, it is a surprise. In order to improve development efficiency, you can go to my GitHub to download the demo

This article GitHub address

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>