Android日历控件方法,Android日历控件的实现方法

本文实例为大家分享了Android日历控件的实现代码,供大家参考,具体内容如下

1、效果图:

ce3dc299f0752c95cb6fb810df3f03de.gif

2、弹窗Dialog:SelectDateDialog:

public class SelectDateDialog {

private static final String TAG = "SelectDateDialog";

private Dialog dialog;

private TextView dateText;

private int selectYear, selectMonth;

private AppCompatActivity mContext;

private DateAdapter adapter;

private List selWeekList = new ArrayList<>();

private List list = new ArrayList<>();

public SelectDateDialog builder(AppCompatActivity mContext, int year, int month) {

this.mContext = mContext;

this.selectYear = year;

this.selectMonth = month;

// 获取Dialog布局

View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_date, null);

// 定义Dialog布局和参数

dialog = new Dialog(mContext, R.style.AlertDialogStyle);

dialog.setCanceledOnTouchOutside(false);//点击外部是否取消

dialog.setCancelable(false);

dialog.setContentView(view);

Window window = dialog.getWindow();

WindowManager.LayoutParams params = window.getAttributes();

params.width = (ScreenUtils.getScreenWidth(mContext));

// params.height = (int) (ScreenUtils.getScreenHeight(mContext) * 0.5);

window.setAttributes(params);

window.setGravity(Gravity.BOTTOM);

RecyclerView recycler = view.findViewById(R.id.recycler_select_date);

dateText = view.findViewById(R.id.date_text);

dateText.setText(year + "年" + month + "月");

//下个月

view.findViewById(R.id.next_month).setOnClickListener(view13 -> {

if (selectMonth > 11) {

selectYear = selectYear + 1;

selectMonth = 1;

} else {

selectMonth++;

}

showNewData(selectYear, selectMonth);

});

//上个月

view.findViewById(R.id.last_month).setOnClickListener(view14 -> {

if (selectMonth < 2) {

selectYear = selectYear - 1;

selectMonth = 12;

} else {

selectMonth--;

}

showNewData(selectYear, selectMonth);

});

list = DataUtils.getCalendar(year, month);

adapter = new DateAdapter(mContext, list);

GridLayoutManager manager = new GridLayoutManager(mContext, 7);

recycler.setLayoutManager(manager);

recycler.setAdapter(adapter);

//取消

view.findViewById(R.id.middle_cancel).setOnClickListener(view1 -> {

dialog.dismiss();

});

//确定

view.findViewById(R.id.middle_determine).setOnClickListener(view1 -> {

initSelect();

});

//设置选中当天

adapter.setNowDay(year, month, DataUtils.getLastMonth(year, month));

return this;

}

private void s

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值