【如何在android中的日历上的特定日期设置点】胸怀万里世界, 放眼无限未来。这篇文章主要讲述如何在android中的日历上的特定日期设置点相关的知识,希望能为你提供帮助。
这是点击日期的代码显示事件,但在事件日期我看不到可见DOT我试图做但没有发生任何事情。
package com.example.mis_internee.mycalentest;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import static android.graphics.Color.RED;
public class MainActivity extends AppCompatActivity {CompactCalendarView compactCalendar;
private SimpleDateFormat dateFormatMonth = new SimpleDateFormat("MMMM- yyyy", Locale.getDefault());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(null);
compactCalendar = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendar.setUseThreeLetterAbbreviation(true);
compactCalendar.setEventIndicatorStyle(Color.BLACK);
compactCalendar.setCurrentDayBackgroundColor(RED);
compactCalendar.getEvents(3223213);
//Set an event for Teachers' Professional Day 2016 which is 21st of OctoberEvent ev1 = new Event(Color.BLACK, 1477040400000L, "Teachers' Professional Day");
compactCalendar.addEvent(ev1);
compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
Context context = getApplicationContext();
if (dateClicked.toString().compareTo("Fri Jan 26 00:00:00 GMT+05:00 2018") == 0) {
Toast.makeText(context, "Teachers' Professional Day", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "No Events Planned for that day", Toast.LENGTH_SHORT).show();
}}@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
actionBar.setTitle(dateFormatMonth.format(firstDayOfNewMonth));
}
});
}
}
提前致谢
答案你在这里设置时间戳
1477040400000L
Event ev1 = new Event(Color.BLACK, 1477040400000L, "Teachers' Professional Day");
compactCalendar.addEvent(ev1);
时间戳
1477040400000L
是Friday, 21 October 2016 09:00:00 GMT +5:30
所以检查那个日期如果你想设置
Fri Jan 26 00:00:00 GMT+05:00 2018
设置Event ev1 = new Event(Color.BLACK,1516924800000L, "Teachers' Professional Day");
compactCalendar.addEvent(ev1);
文章图片
推荐阅读
- 在Android Studio导入期间维护目录结构
- RecyclerView smoothScroll位于中心位置。安卓
- 在Android中创建用户可选择的字符串列表的最简单方法是什么()
- 使用回收视图时无法在Android模拟器中看到应用栏
- Android TV RecyclerView重点互动
- 如何解决无法识别应用的tf.app.run()错误()
- 重复条目(android / support / v7 / recyclerview / extensions / ListAdapter.class [复制])
- 适用于所有移动设备的Webview App并上传到Play商店
- Android WebView - 重置HTTP会话