Reputation: 103
I add datepicker to my application but my problem the shadow for the dialog have white background , use Android 21 for compile .
please help me to remove white background ...
Upvotes: 3
Views: 4746
Reputation: 2295
for me it didn't help to set the window background to transparent, this made all my datePicker dialog with transparent not only the ugly border.. :(
what helped me is to set also the regular background to the color I wanted and the windowBackground to transparent. this is my style:
<style name="pickerDialogDark" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">?attr/dialogBackground</item>
<item name="android:textColor">@color/colorSimpleGreen</item>
<item name="colorAccent">@color/colorGreen</item>
<item name="colorPrimaryDark">@color/colorBlack</item>
<item name="android:textColorSecondary">@color/colorSimpleGreen</item>
<item name="android:headerBackground">?attr/dialogBackground</item>
</style>
Upvotes: 1
Reputation: 1046
It may be late but will help.
You have to add transparent background of you dialog. Here is how you can do this:
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));
}
};
Upvotes: 1
Reputation: 1
DatePickerDialog dialog = new DatePickerDialog(mContext, android.R.style.Theme_Holo_Light_Dialog_NoActionBar, mDateSetListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
dialog.getWindow().setBackgroundDrawableResource(R.color.transparency);
dialog.show();
Upvotes: 0
Reputation: 31
Add a new style in the default style (not style-21)
<style name="Your style" parent="@android:style/Widget.DeviceDefault.DatePicker">
<item name="android:textColor">@color/app__primary_color</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:gravity">center</item>
<item name="android:layout_gravity">center</item>
Upvotes: 0
Reputation: 997
I had the same problem,
First Solution I have done :
I end up giving this theme in the DatePickerDialog builder. What's important is the windowBackground set to transparent.
<style name="Theme.Yp.DatePicker" parent="@android:style/Widget.DeviceDefault.DatePicker">
<item name="android:textColor">@color/color_accent</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:gravity">center</item>
</style>
Second and Final Solution :
I finished by using the DatePickerDialog.THEME_DEVICE_DEFAULT_LIGHT
that works just fine. We didn't use a lot of styling so it was ok.
Upvotes: 4
Reputation: 6530
You have a "bug" in your themes.xml
or styles.xml
material design support library is not working properly with dialogs.
So remove the specific dialog code or separate it in different versions.
Trying to explain a little bit further.
Generally when we extend the original application theme we have an themes.xml
and/or styles.xml
files under the values
folder. In there code you will find something like these:
Application theme:
<style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- ... other styling values ... -->
<!-- Dialog attributes -->
<item name="dialogTheme">@style/MyTheme.Dialog</item>
<!-- AlertDialog attributes -->
<item name="alertDialogTheme">@style/MyTheme.Dialog</item>
<!-- ... other styling values ... -->
</style>
Custom dialog theme:
<style name="MyTheme.Dialog" parent="@style/Theme.AppCompat.Light.Dialog">
<!-- some styling values here -->
</style>
What needs customization is the parent
of the MyTheme.Dialog
this Theme.
AppCompat
.Light.Dialog
does not work properly for all android versions it may work for Lollipop but does not work for KitKat, or the opposite.
values-v21
and define the parent of the dialog accordingly, so that it work for both versions.You can apply some other workarounds regarding the customization of the style, in order for this to work.
If you would like further research, or theme customization ideas take a look at the source of android theme.xml here.
Upvotes: 1