Reputation: 470
I am using Android's native DatePicker in the following way and it is working fine but the view is somehow coming to be not proper.
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
DatePickerDialog dialog;
@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);
dialog= new DatePickerDialog(getActivity(), this, year, month, day);
dialog.getDatePicker().setMinDate(new Date().getTime());
// Create a new instance of DatePickerDialog and return it
return dialog;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Doing some stuff here
}
}
And, calling it like this :
DialogFragment datePickerFragment = new DatePickerFragment();
datePickerFragment.show(getActivity().getFragmentManager(), "startDate");
Upvotes: 2
Views: 487
Reputation: 470
I solved my problem by removing this line from v21/styles.xml file.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--<item name="android:background">@android:color/white</item>-->
</style>
Because of this line all custom views(fragments, dialogs, etc.) were bydefault picking a white background.
Upvotes: 4