11

the problem is that my date picker having an ugly White background behind the date picker

White background

i just want that background to Disappear

this is My code

 public void selectDate(View view) {
    DialogFragment newFragment = new SelectDateFragment();
    newFragment.show(Master_.fragmentManager, "DatePicker");
}

public void populateSetDate(int year, int month, int day) {


        Birthdate.setText(year + "-" + month + "-" + day);

}

public class SelectDateFragment extends DialogFragment implements
        DatePickerDialog.OnDateSetListener {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Calendar calendar = Calendar.getInstance();
        int yy = calendar.get(Calendar.YEAR);
        int mm = calendar.get(Calendar.MONTH);
        int dd = calendar.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dialog =new DatePickerDialog(mActivity,R.style.jehadStyle, this, yy, mm, dd);  
    dialog.getDatePicker().setMaxDate(calendar.getTimeInMillis());  

    return dialog ;
    }

    public void onDateSet(DatePicker view, int yy, int mm, int dd) {
        populateSetDate(yy, mm + 1, dd);
    }
}

and this is my style

 <style name="jehadStyle" parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar">
    <item name="android:textColor">@android:color/black</item>

</style>
Jehad
  • 472
  • 2
  • 10
  • 24

4 Answers4

25
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

add this to your DatePickerDialog

Arun Salaria
  • 984
  • 6
  • 20
  • 3
    Works like a charm on old API. At least with API23 -> the Dialog background become totally transparent :s -> don't use it starting API 21 – Tobliug Mar 29 '16 at 12:54
  • @Tobliug: what is the solution which can work across all the APIs? – Mehul Joisar Jun 16 '16 at 05:54
  • @MehulJoisar As far as I know, no solution across all API. I use different style regarding the API level – Tobliug Jun 22 '16 at 14:38
3

try like this,

<style name="jehadStyle" parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:background">@null</item>
    </style>

hope it will help you

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19
3
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

use with DatePickerDialog

Edric
  • 24,639
  • 13
  • 81
  • 91
-1

Try with this

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

add this line above "return dialog".

Jigar Shekh
  • 2,800
  • 6
  • 29
  • 54