DatePickerDialog displays with two borders - android

I have a question about DatePickerDialog displaying.
I want to create date picker dialog with "HoloDialog" theme like this:
DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog, reservationDate, 2014, 1, 1);
Then I will see this result:
As you can see, dialog is displayed with "two borders" around.
I want to create the same dialog as displayed here, but with one border around. Is it possible?

Assuming I understand your question correctly, I think I found a way. Here, we anonymously subclass DatePickerDialog to override onCreate() and set a transparent background for the window.
DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog,
reservationDate, 2014, 1, 1) {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
};
You could also do this with a custom theme instead. For example:
<style name="HoloDialog" parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then pass that in the DatePickerDialog's constructor:
DatePickerDialog dpd = new DatePickerDialog(this, R.style.HoloDialog,
reservationDate, 2014, 1, 1);

Related

DatePickerDialog Issue in Android

I am unable to see the initials of Day in DatePickerDialog
What I want is :
The code I am using for showing dialog is :
DatePickerDialog dialog = new DatePickerDialog(context, startingDateSetListener,
starting_date_object.getYear(),
starting_date_object.getMonthOfYear()-1,
starting_date_object.getDayOfMonth());
dialog.getDatePicker().setMaxDate(ending_date_object.getMillis());
dialog.show();
The days are probably there but their textColor is the same as the background so you can't see them. This has to do with the style/theme of the dialog.
Create a theme in styles.xml like:
<style name="DatePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#color/your_accent_color</item>
<item name="colorControlActivated">#color/your_control_activated_color</item>
</style>
and initialize the DatePickerDialog by supplying the theme:
DatePickerDialog dialog = new DatePickerDialog(context,
R.style.DatePickerTheme,
startingDateSetListener,
starting_date_object.getYear(),
starting_date_object.getMonthOfYear()-1,
starting_date_object.getDayOfMonth());

Android : Custom colors for DatePickerDialog

I'm using a DatePickerDialog in a DialogFragment, which works fine.
I would like to change the colors of:
the background of the action bar
the background of the buttons
the dividers
Here is my DialogFragment:
public class DatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// init :
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTest, this, year, month, day);
datePickerDialog.getDatePicker().setBackgroundColor(0xFF500000);
return datePickerDialog;
}
...
}
And here is the style:
<style name="DatePickerDialogTest" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:textColorPrimary">#FF00FF00</item>
<item name="colorAccent">#FFFF0000</item>
<item name="android:divider">#android:color/holo_purple</item>
</style>
Every color I use displays properly, except for the backgrounds of the action bar, buttons and dividers.
Is there any way I can easily change those colors?
Thanks.

Blank white space around Timepicker dialog

I am trying to create a time picker for my application..
and when setting the theme to Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
I am getting this output
I am getting a blank space around the dialog box
This is not happening when I am setting it to use the parent activity's theme which is appcompat.noactionbar
//not happening here
return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
Here is my timepicker code
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{
#Override
public Dialog onCreateDialog(Bundle savedInstanceState){
//Use the current time as the default values for the time picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourView=true;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String formattedTime = sdf.format(c.getTime());
Log.d("time", formattedTime);
//Create and return a new instance of TimePickerDialog
// return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
return new TimePickerDialog(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth,this, hour, minute,is24HourView );
}
I know this is old, but here is a solution.
You could make a custom theme in styles.xml with your chosen theme as a parent, and set it's android:windowBackground attribute to #android:color/transparent:
<style name="TimePickerDialogStyle" parent="#android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar.MinWidth">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then pass your custom theme to the TimePickerDialog constructor:
new TimePickerDialog(getActivity(), R.style.TimePickerDialogStyle, this, hour, minute, is24HourView);
Change:
android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
with
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
or
AlertDialog.THEME_HOLO_LIGHT
It should work

how to create DatePicker with plus minus sign in android

I am creating an application in which I am using androids DatePicker.I want the DatePicker to have plus and minus sign rather then the spinner view.can anybody tell me how to get it.
The datepicker that i have used has got spinner view.I am new in android development so please if somebody knows the answer, help me.
Thanks in advance
Try this to specify the theme for your dialog on Android Honeycomb+, in this example the Holo.Light theme:
DatePickerDialog datePicker;
DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener()
{
.
.
.
};
if (Build.VERSION.SDK_INT < 11)
{
datePicker = new DatePickerDialog(context, dateSetListener, ...)
}
else
{
// specify the Holo Light Theme for this dialog on Honeycomb+
datePicker = new DatePickerDialog(context, DatePickerDialog.THEME_HOLO_LIGHT, dateSetListener, ...)
}
datePicker.show();

Change Divider Color OR theme of Android DatePicker Dialog

I am tying to change the divider color of the DatePicker Dialog.
I already checked all duplicate questions but i didn't get anything which is working.
I want to use orange color instead of this blue color of this divider.
Right now my datepicker looks like this and i also want to remove this background of whole date picker.
I used this code for datepicker dialog
final Calendar calendarDate = Calendar.getInstance();
DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calendarDate.set(Calendar.YEAR, year);
calendarDate.set(Calendar.MONTH, monthOfYear);
calendarDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
}
};
DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
dateSetListener, calendarDate.get(Calendar.YEAR), calendarDate
.get(Calendar.MONTH), calendarDate
.get(Calendar.DAY_OF_MONTH));
datePickerDialog.getDatePicker().setCalendarViewShown(false);
datePickerDialog.show();
Screeshot :
Use Custom Style to change the divider color/theme from your drawable image as below:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="YourTheme" parent="#android:style/Theme">
<item name="android:divider">#drawable/dialog_divider_color</item>
</style>
</resources>
and update the AndroidManifest.xml file with the android:theme="YourTheme" for the <activity/>

Categories

Resources