Im using a DatePickerDialog on my app, and when it shows it looks like this
Im trying to change the look of it, to look like this one
This is how i declare my picker:
DatePickerDialog datepicker = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);
According to a tutorial i was reading, if we pass AlertDialog.THEME_DEVICE_DEFAULT_LIGHT it should display the calendar like i want, but it does not work. Do i need something else?
Edit
Seems it might be an issue with Huawei(brand of the phone i was using) according to this
From the official docs -
When the DatePicker_datePickerMode attribute is set to calendar, the month and day can be selected using a calendar-style view while the year can be selected separately using a list.
According to datePickerMode doc -
Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is calendar.
So, if you are using the material theme in your Activity, then pass 0 in themeResId. This will make the dialog use the parent context's default alert dialog theme.
DatePickerDialog datepicker = new DatePickerDialog(getActivity(),
0 ,this,year,month,day);
Otherwise, you can use Theme_Material_Dialog_Alert or Theme_Material_Light_Dialog_Alert.
DatePickerDialog datepicker = new DatePickerDialog(getActivity(),
R.style.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);
Related
I manage to add events in google calendar and viewing the list of events but my problem is how can i sync those events to my custom calendar and the day must have a different color or any mark so that the user would know that the day has a event.
Try to check this documentation if this is the one you are looking for about syncing. Now, about the color of the events, you can set this different color in creating events by using the parameter colorId. For more information, check this SO question on how to do it in android code.
Hey guys having issues with customizing the date picker in android. Here's an image of my current date picker.
As I've highlighted in black two things I'm having issues with.
Is there away to remove the header of the date picker? I just want the calendar part.
Is there a way to adjust the date picker so that it'll fit the width of any screen it's on?
I'm using a date picker not a date picker dialog.
to remove the header
datePickerDialog.setTitle("");
see the link,
Remove Title from DatePickerDialog
to get fullscreen, set android:layout_width to match_parent
I am looking for way to get a calendar view with Event added on specific date something like the below:
And when I click on the calendar date another activity has to be opened?
Can the default calendar View help me doing the same or is there any other API that can help get the result like above?
Let me know!
Thanks!
You can use default calender library like
CalendarView
or you can use Caldroid
You can use default calendarview, I have used material calendarview for similar result.
You can even add events in text form as well as you can show drawable images with texts there.
See the line of code:
List<EventDay> events = new ArrayList<>();
events.add(new EventDay(calendar, CalendarUtils.getDrawableText(this, "₹"+wonAmt, Typeface.DEFAULT_BOLD, R.color.green, 8)));
I'm in the process of learning to develop apps in Android, and I am a bit confused by the docs. I have an activity with a button which is initially filled with a date I got from the Calendar class. When the user clicks on this button, a DatePicker dialog would show up and allow me to set a new date, which should then be written back to that button's text and be used for further processing.
I see the Android Pickers documentation suggests you to create a DatePickerFragment extending DialogFragment, like reproduced here:
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
I understood the date set on the dialog will be made available from the onDateSet method, which is the implementation of the DatePickerDialog.OnDateSetListener interface, but what I fail to see is why not just call DatePickerDialog directly from the main activity? (in my case it is just what I ended up doing and it works fine...).
From my novice point of view it seems that implementing a DatePickerFragment is acting like an apparently unnecessary mid layer between Activity and the DatePickerDialog, making it harder than it should be in the sense that for communicating the date set on DatePickerFragment.onDateSet to the main activity would require the interface to be also implemented by the main activity and to communicate the initial date to the fragment I would have to do it through a Bundle object, like shown here.
Is this just a matter of documentation trying to be generalist and start off from a fragment instead of activity (I get the feeling a fragment is a bit like a lightweight activity) or there is really some advantage or thing I'm missing so I don't call the dialog directly from the activity?
Since you're new to Android and haven't yet run into it, let me break it to you: handling orientation changes in Android is a pain. To make it short: the Activity gets recreated every time you change orientation. And all your data members like Dialogs become null.
To combat this there are a couple of ways to handle orientation changes and having a "retained fragment" is one of them. So a DialogFragment is a flavour of this "retained fragment" (don't quote me on this), that doesn't get destroyed on orientation change.
More on this here: http://developer.android.com/guide/topics/resources/runtime-changes.html
I created an android calendar widgets. but I'm just wondering.. is it possible to override the method of CalendarView? what I really wanted is to display only the current month and daygridview not the previews days and next month days.. and I also want to remove the scrollView that allow the user to scroll up and down for the previous and next month.. I just want to have a simple calendar... Is there any body can help me please?..
this is the CalendarView that I wanted to customized..
XML CalendarView ScreenShoots
So then make a class that extends CalendarView and override according methods. There should not be a problem with it.
You could just create a gridView and set the # of columns as 7 for the # of days. Create an adapter that would then extend BaseAdapter. And in that class, you could set the # of grid cells as 42 as the max. possible grid cells is 7*6. Once done, as part of the getView() method, you could create a textview for each grid cell and fill that with the day of the month.
For setting the weekdays at the top, you could create another gridView with the same specs and set that as the headerView.