impossible
impossible

Reputation: 2500

Customize style Theme.Holo.Light.Dialog.MinWidth for DatePicker

I am using datePicker to input a date.

<style name="DatePickerTheme" parent="@android:style/Theme.Holo.Light.Dialog.MinWidth">
    <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>

and in Activity.java

public void showDatePickerDialog(View v) {
        DialogFragment newFragment = new Login.DatePickerFragment();
        newFragment.show(getSupportFragmentManager(), "datePicker");
    }

    public static class DatePickerFragment extends DialogFragment
            implements DatePickerDialog.OnDateSetListener {

        @NonNull
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new DatePickerDialog(getActivity(), R.style.DatePickerTheme, this, 1995, 0, 1);
        }

        public void onDateSet(DatePicker view, int year, int month, int day){                
                    dateSelected = year+"-"+month+"-"+day;

        }
    }

Issue is that I am getting a background tile, which I dont want.

I am getting this

but I want

the edited one

Upvotes: 5

Views: 6470

Answers (2)

Tamashii
Tamashii

Reputation: 81

This line can help:

datePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

Upvotes: 8

Leang Socheat
Leang Socheat

Reputation: 1174

I just solved problem above with kotlin. For style AlertDialog.THEME_HOLO_DARK which has deprecated also instead below code.

val c = Calendar.getInstance()
    val year = c.get(Calendar.YEAR)
    val month = c.get(Calendar.MONTH)
    val day = c.get(Calendar.DAY_OF_MONTH)

    val dpd = DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth,
            DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
        var calendar = GregorianCalendar(year,monthOfYear,dayOfMonth)
        setDate(calendar)

    }, year, month, day)
    dpd.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    dpd.show()

Upvotes: 2

Related Questions