Needs
1.Dependencies
dependencies{implementation 'com.github.sundeepk:compact-calendar-view:1.9.1'
}2.CalendarActivity.java3.activity_calendar.xml4.drwaple >>>>> layout_shape.xmlStep :1Apply dependencyimplementation 'com.github.sundeepk:compact-calendar-view:1.9.1'
Step :2activity_calendar.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"> <android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/colorPrimary"android:theme="@style/AppTheme.AppBarOverlay"> <ImageViewandroid:id="@+id/image_back"android:layout_width="30dp"android:layout_height="20dp"android:layout_marginLeft="20dp"android:src="@mipmap/back_arrow" /> <TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="20dp"android:text="Job Detail"android:textColor="@android:color/white"android:textSize="17dp"android:textStyle="bold" /> <TextViewandroid:id="@+id/text_today"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center|right"android:padding="10dp"android:text="Today"android:textColor="@android:color/white"android:textSize="15dp" /> </android.support.v7.widget.Toolbar> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="400dp"android:layout_margin="10dp"android:background="@drawable/layout_shape"android:gravity="center"android:orientation="vertical"> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="60dp"android:gravity="center"android:orientation="horizontal"> <LinearLayoutandroid:id="@+id/layout_right"android:layout_width="40dp"android:layout_height="match_parent"android:gravity="center"> <ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:background="@mipmap/your image" /> </LinearLayout> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"> <TextViewandroid:id="@+id/text"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="Date"android:textColor="@color/your color"android:textSize="17dp"android:textStyle="bold" /> </LinearLayout> <LinearLayoutandroid:id="@+id/layout_left"android:layout_width="40dp"android:layout_height="match_parent"android:gravity="center"> <ImageViewandroid:layout_width="20dp"android:layout_height="20dp"android:background="@mipmap/your image" /> </LinearLayout> </LinearLayout> <Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/your color" /> <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="0.2"> <com.github.sundeepk.compactcalendarview.CompactCalendarViewandroid:id="@+id/compactcalendar_view"android:layout_width="match_parent"android:layout_height="320dp"android:layout_margin="5dp"app:compactCalendarBackgroundColor="@android:color/white"app:compactCalendarCurrentDayBackgroundColor="@color/your color" app:compactCalendarCurrentSelectedDayBackgroundColor="@color/your color" app:compactCalendarMultiEventIndicatorColor="@color/your color" app:compactCalendarTargetHeight="360dp"app:compactCalendarTextColor="@android:color/black"app:compactCalendarTextSize="15dp" /> </LinearLayout>Step :3CalendarActivity.javapublic class CalendarActivity extends AppCompatActivity { CompactCalendarView compactCalendarView; private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM-YYYY", Locale.getDefault()); private SimpleDateFormat DateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); SimpleDateFormat sdf; TextView tx_date, tx_today; LinearLayout ly_detail; LinearLayout ly_left, ly_right; Calendar myCalendar; ImageView im_back; Date c; SimpleDateFormat df; String formattedDate; String[] dates = new String[0]; RecyclerView recyclerView; TextView tx_item; CalendarAdapter adapter; String[] day={"10","20","21","25","27"}; String[] month={"10","10","11","11","12"}; String[] year ={"2018","2018","2018","2018","2018"}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calendar); init(); calendarlistener(); Setdate(); tx_date.setText(""+formattedDate); ly_right.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) { compactCalendarView.showCalendarWithAnimation(); compactCalendarView.showNextMonth(); } }); ly_left.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) { compactCalendarView.showCalendarWithAnimation(); compactCalendarView.showPreviousMonth(); } }); tx_today.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) { Intent intent = new Intent(CalendarActivity.this, CalendarActivity.class); startActivity(intent); finish(); } }); im_back.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) { finish(); } }); } //variable initializationpublic void init() { compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view); tx_date = (TextView) findViewById(R.id.text); ly_left = (LinearLayout) findViewById(R.id.layout_left); ly_right = (LinearLayout) findViewById(R.id.layout_right); im_back = (ImageView) findViewById(R.id.image_back); tx_today = (TextView) findViewById(R.id.text_today); ly_detail = (LinearLayout) findViewById(R.id.layout_detail);}//calendar methodpublic void calendarlistener() { compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() { @Overridepublic void onDayClick(Date dateClicked) { if ( DateFormat.format(dateClicked).equals("2018-11-21")){ Toast.makeText(getApplicationContext(),DateFormat.format(dateClicked)+" This day your brother birth day ",Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(),DateFormat.format(dateClicked)+" In This day no Events Available",Toast.LENGTH_LONG).show(); } } @Overridepublic void onMonthScroll(Date firstDayOfNewMonth) { compactCalendarView.removeAllEvents(); Setdate(); tx_date.setText(simpleDateFormat.format(firstDayOfNewMonth)); } }); } //get current datepublic void Setdate() {c = Calendar.getInstance().getTime(); df = new SimpleDateFormat("yyyy-MM-dd"); formattedDate = df.format(c); compactCalendarView.setUseThreeLetterAbbreviation(true); sdf = new SimpleDateFormat("MMMM yyyy"); myCalendar = Calendar.getInstance(); for (int j = 0; j < month.length; j++) { int mon = Integer.parseInt(month[j]); myCalendar.set(Calendar.YEAR, Integer.parseInt(year[j])); myCalendar.set(Calendar.MONTH, mon - 1); myCalendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day[j])); Event event = new Event(Color.RED, myCalendar.getTimeInMillis(), "test"); compactCalendarView.addEvent(event); } } }
Step 4:
drawaple >>>>>>> layout_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> <solid android:color="@android:color/white"/> <stroke android:width="1dp"
android:color="@color/colorPrimary"/> <corners android:radius="5dp"/> </shape>
Amazing blog! customised new year calendar!!Create a Photo Calendar of New Year for your Wall from your best photos Online.Use our online calendar creator to make your own calendars with your own, print your photo, etc.
ReplyDelete