I am using a time picker dialog in my app. I am also using appcompat to give my app material design theme. The dialog however stays with the default teal accent color (my accent is a light blue).
so in my code I tried setting the dialog theme to my own and it works accept it makes it fullscreen
mTimePicker = new TimePickerDialog(ctx, R.style.AppTheme new TimePickerDialog.OnTimeSetListener() {->}, hour, minute, DateFormat.is24HourFormat(context));
does anyone know how to set the TimePickerDialog to show correctly with my colors instead of the default ones?
This can be easily achieved from xml (5.0+ only)
v21/themes.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme"
parent="MyTheme.Base">
<item name="android:dialogTheme">#style/Theme.Dialog</item> <!-- TimePicker dialog -->
<item name="android:alertDialogTheme">#style/Theme.Dialog</item> <!-- Alert dialog -->
</style>
<style name="Theme.Dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">#color/...</item>
<item name="android:colorPrimary">#color/...</item>
<item name="android:colorPrimaryDark">#color/...</item>
</style>
</resources>
Edit
Please note that as of Android Support Library 22.1.0 there is a new AppCompatDialog available! http://android-developers.blogspot.de/2015/04/android-support-library-221.html
You can override the colors using:
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
R.style.themeOnverlay_timePicker, //theme overlay
timeSetListener,
hours,minutes,true);
with:
<style name="themeOnverlay_timePicker" parent="#style/ThemeOverlay.MaterialComponents.Dialog">
<item name="colorControlActivated">#color/....</item>
<item name="colorAccent">#color/....</item>
<item name="android:textColorPrimary">#color/.....</item>
<item name="android:textColorSecondary">#color/.....</item>
</style>
If you are using an AppCompat theme use ThemeOverlay.AppCompat.Dialog as parent.
Related
I have a date picker dialog that I use in spinner mode. This is the theme used by the date picker dialog.
<style name="CustomDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.DatePicker">
<item name="android:datePickerMode">spinner</item>
This works fine when I use it when "Dark Mode = off". But it does not reverse the colors when "Dark Mode = on". Irrespective of the Dark Mode this is how the dialog looks like
I tried changing the parent theme to Theme.AppCompat.DayNight.Dialog. Now the dialog looks like this when "Dark Mode = on"
How do I make the DatePickeDialog (in spinner mode) compatible with Dark Mode?
Please try without specifying the parent theme, this works for me. but your dialog will be full screen for this in your theme add android: windowIsFloating = true. this to center the dialog on the screen and it becomes like a normal Dialog
this is my theme :
<style name="CustomDatePickerDialogTheme">
<item name="android:datePickerStyle">#style/MyDatePickerStyle</item>
<item name="android:windowIsFloating">true</item>
</style>
<style name="MyDatePickerStyle" parent="#android:style/Widget.Material.DatePicker" tools:targetApi="lollipop">
<item name="android:datePickerMode">spinner</item>
</style>
just need to change the theme color setting as per your requirement do the below changes and do comment if not work. do your code in your parent theme this is general style
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorAccent">#FC6C2D</item> ---> I used orange color here to display the picker dialog in orange color.
<item name="android:textColorPrimary">#000000</item>
<item name="android:textColorSecondary">#000000</item>
</style>
I know this post is duplicate but previously I didn't get any positive response that why re-posting it.
Currently the date picker is look like this.
I want to change the color date color ( currently set to black.)
Datepicker theme.
<style name="myDatePickertheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:headerBackground">#color/white</item>
<item name="android:textColorPrimary">#color/primary_text</item>
#color/white
Solution Tried:
#color/white
in the custom theme.
Min api=17
App theme
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#color/primary_background</item>
<item name="android:colorPrimaryDark">#color/primary_background</item>
<item name="android:navigationBarColor">#color/primary_background</item>
<item name="android:popupBackground">#color/primary_background</item>
<item name="android:alertDialogTheme">#style/myDialog</item>
<item name="android:datePickerDialogTheme">#style/myDatePickertheme</item>
</style>
Beside the above setting, I also use all the customisation provided by this link
I have declared material theme in my styles.xml.
<style name="SignUpMaterialTheme.Base"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/splashBg</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorControlNormal">#f2efea</item>
<item name="colorControlActivated">#f2efea</item>
</style>
I am using EditText with TextInputLayout, so when I click on it I am showing a DatePickerDialog. Now the problem I am facing is the date selected color is showing as white, but I have already declared the color accent in my style. When I tried removing the colorControlNormal and colorControlActivated it shows the date selected as the accent color but the TextInputLayout color changes to black. What to do?
Any suggestions?
for light color:
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_DARK,this,year,month,day);
for dark color:
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);
I am unable to change the selector color and other parts of the TimePicker.
So far, I can change header color and background but I am unable to change the innercircle and the textcolor.
Change custom theme link.
My code :
<TimePicker
android:id="#+id/tp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="clock"
android:headerBackground="#565466"
android:amPmBackgroundColor="#500126"
android:numbersBackgroundColor="#57e326"
android:numbersTextColor="#995394"
android:numbersSelectorColor="#675543"
android:textColorSecondary="#897530"
android:textColorPrimary="#359875"
/>
Basic mode
All you have to do is set your accent color in your Activity's theme:
<item name="colorAccent">#3333cc</item>
This will set all the colors for you so you wouldn't mess up the styling.
(This also means that you shouldn't set values like amPmBackgroundColor on your TimePicker directly, let Android do the things for you.)
Advanced mode
If you want to specify all the possible values separately, do the following:
First define this in your Activity's theme:
<item name="android:timePickerStyle">#style/Theme.MyTheme.TimePicker</item>
Then create the appropriate style:
<style name="Theme.MyTheme.TimePicker" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">clock</item>
<item name="android:headerBackground">#ff555555</item>
<item name="android:numbersTextColor">?android:attr/textColorPrimaryActivated</item>
<item name="android:numbersInnerTextColor">?android:attr/textColorSecondaryActivated</item>
<item name="android:numbersSelectorColor">?android:attr/colorControlActivated</item>
<item name="android:numbersBackgroundColor">#ff555555</item>
<item name="android:amPmTextColor">?android:attr/textColorSecondary</item>
</style>
Note that numbersInnerTextColor is only available from API level 23 and other styles (e.g. headerTextColor) can't be set (or at least I couldn't make it work).
I'd advise against using the "advanced" mode as the TimePicker should have the same colors as the containing Activity and doing otherwise might impact your UX in a bad way.
TimePicker material style:
TimePickerDialog material style with custom colors
<style name="MyTimePickerDialogStyle" parent="#style/ThemeOverlay.AppCompat.Dialog.Alert">
<item name="showTitle">false</item>
<item name="colorControlActivated">#ffd600</item>
<item name="colorAccent">#b71c1c</item>
<item name="android:textColorPrimary">#43a047</item>
<item name="android:textColorSecondary">#f44336</item>
</style>
TimePicker widget style
<style name="MyTimePickerWidgetStyle" parent="#android:style/Widget.Material.TimePicker">
<item name="android:headerBackground">#ffe082</item>
<item name="android:numbersTextColor">#b71c1c</item>
<item name="android:numbersInnerTextColor">#f44336</item>
<item name="android:numbersSelectorColor">#33691e</item>
<item name="android:numbersBackgroundColor">#ef9a9a</item>
<item name="android:amPmTextColor">#9c27b0</item>
</style>
For more information on TimePicker see http://www.zoftino.com/android-timepicker-example
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 ...
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.
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.
With a simple run of the app in each platform you can easily find out in which version it works.
Then you can create a different folder for 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.
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));
}
};
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>
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>
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();