57849

Change the color of selected date only in date picker android

Question:

<a href="https://i.stack.imgur.com/UQZ0T.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/UQZ0T.png" data-original="https://i.stack.imgur.com/UQZ0T.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

I am using date picker and I need to style it with different colors. All things are working fine except the selected date color. The thing is selected date color takes "android:textColorPrimaryInverse" as default which in my case is red , background of the dialog is white and the "android:colorControlHighlight" and "android:colorControlActivated" is also red.

This means the selected text color doesn't show.I need that to be shown as white but the issue is if I change"android:textColorPrimaryInverse" to white my title won't appear as the background is white.

here is my style file :

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">@color/color_white</item> <item name="android:textColorPrimaryInverse">@color/red</item> <item name="android:textColorSecondaryInverse">@color/red</item> <item name="android:datePickerStyle">@style/MyDatePickerStyle</item> <item name="buttonBarButtonStyle">@style/DialogButtonStyle</item> <item name="android:colorControlHighlight">@color/red</item> <item name="android:colorControlActivated">@color/red</item> </style>

and this is how I show my dialog

new DatePickerDialog(mActivity, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //DO SOMETHING } }, 2015, 02, 26).show();

Answer1:

Use;

<item name="android:textColorPrimaryInverse">@color/white</item> <item name="android:colorControlActivated">@color/red</item>

Answer2:

Try below code

<style name="CustomDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorAccent">@color/accent</item> <item name="android:datePickerStyle">@style/CustomDatePickerStyle</item> <item name="android:colorAccent">@color/primDark</item> </style> <style name="CustomDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker"> <item name="android:headerBackground">@color/prim</item> <item name="android:calendarTextColor">@color/primDark</item> <item name="android:dayOfWeekBackground">@color/primDark</item> <item name="android:yearListSelectorColor">@color/accent</item> <item name="android:datePickerMode">calendar</item> </style>

Answer3:

What you need to deal with in your style is 'colorControlActivated' and 'selectableItemBackgroundBorderless' . Check the code snippet below:

<item name="colorControlActivated">#@color/Green</item> <item name="android:selectableItemBackgroundBorderless">@color/LightPink</item>

Current date will be 'Green' and selected date will have a 'LightPink' boardering background

Recommend

  • Android - how to set dialog's outer margin
  • How to set TextView text color to specific Theme color
  • Select multiple dates in Android DatePickerDialog
  • COM - [in] parameter as SAFEARRAY(STRUCT)
  • JavaScriptCore External Arrays
  • How to create two column output from a single column
  • How can I get the choice “H2” back in the H2 consol?
  • Approximate Order-Preserving Huffman Code
  • Force show.bind execution
  • $wpdb not working in file of WordPress plugin
  • Disable Enter in editText android
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • Different response to non-authenticated users and AJAX calls
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • javascript inside java/jsp code
  • Sending data from AppleScript to FileMaker records
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • To display the title for the current loaction in map in iphone
  • Web-crawler for facebook in python
  • Calling of Constructors in a Java
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Data Validation Drop Down Box Arrow Disappearing
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • trying to dynamically update Highchart column chart but series undefined
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • coudnt use logback because of log4j
  • Linking SubReports Without LinkChild/LinkMaster
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal