Closed Rainer-Lang closed 8 years ago
Can you post your project's styles.xml
?
styles.xml
<resources>
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
<item name="actionBarTheme">@style/AppTheme.ActionBarTheme.Light</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="sublimePickerStyle">@style/MySublimePickerStyle</item>
</style>
<style name="AppTheme.ActionBarTheme.Light" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlActivated">#FFffffff</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>
<style name="MySublimePickerStyle" parent="SublimePickerStyleLight">
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
</style>
<style name="SublimePickerDefault">
<item name="sublimePickerStyle">@style/MySublimePickerStyle</item>
</style>
<style name="ShowExtendedBg">
<item name="sublimePickerStyle">@style/SPExtendedBg</item>
</style>
<style name="SPExtendedBg" parent="MySublimePickerStyle">
<item name="spButtonLayoutStyle">@style/BLExtendedBgImpl</item>
</style>
<style name="BLExtendedBgImpl" parent="ButtonLayoutStyle">
<item name="buttonModeSwitcherButtonStyle">@style/SInvertedButtonBarButtonStyle</item>
<item name="extendPartitionThroughButtonBar">true</item>
<item name="extendedPartitionBgColor">?attr/colorAccent</item>
<item name="buttonInvertedBgColor">?attr/colorAccent</item>
<item name="buttonPressedInvertedBgColor">@color/ripple_material_dark</item>
</style>
<!-- ShowSingleMonthPerPosition -->
<style name="ShowSingleMonthPerPosition">
<item name="sublimePickerStyle">@style/SPSingleMonthPerPosition</item>
</style>
<style name="SPSingleMonthPerPosition" parent="MySublimePickerStyle">
<item name="spMonthViewStyle">@style/MVSingleMonthPerPositionImpl</item>
</style>
<style name="MVSingleMonthPerPositionImpl" parent="MonthViewStyle">
<item name="showSingleMonthPerPosition">true</item>
</style>
<!-- ShowExtendedBg + ShowSingleMonthPerPosition -->
<style name="ShowExtendedBgAndSingleMonthPerPosition">
<item name="sublimePickerStyle">@style/SPExtendedBgAndSingleMonthPerPosition</item>
</style>
<style name="SPExtendedBgAndSingleMonthPerPosition" parent="MySublimePickerStyle">
<item name="spMonthViewStyle">@style/MVSingleMonthPerPositionImpl</item>
<item name="spButtonLayoutStyle">@style/BLExtendedBgImpl</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
</resources>
Your styles.xml
looks fine. I can see some style definitions that are not needed. But, it should be working. What specific background are you trying to change? And what is the expected vs current output?
Note: The sample project included some style definitions which will not be needed for a regular project. I tried to explain this in comments here: https://github.com/vikramkakkar/SublimePicker/blob/master/app/src/main/java/com/appeaser/sublimepicker/Sampler.java#L290
I agree that the explanation is not very good. All you need is:
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.DarkActionBar">
....
....
<item name="sublimePickerStyle">@style/MySublimePickerStyle</item>
</style>
<style name="MySublimePickerStyle" parent="SublimePickerStyleLight">
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
</style>
colorAccent
is used as the default for headerBackground
. So, you should be seeing @color/colorAccent
as the header background for the DatePicker. Now, if you want the DatePicker and TimePicker to have different header backgrounds, change MySublimePickerStyle
:
<style name="MySublimePickerStyle" parent="SublimePickerStyleLight">
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<!-- Change DatePicker's style -->
<item name="spDatePickerStyle">@style/MyDatePickerStyle</item>
</style>
<!-- `MyDatePickerStyle` inherits from `SublimeDatePickerStyle`. So, we don't
have to define all of the attributes used by DatePicker. We only change the one
we want to. -->
<style name="MyDatePickerStyle" parent="SublimeDatePickerStyle">
<item name="headerBackground">@color/colorHeaderBackgroundDatePicker</item>
</style>
Now, DatePicker
will use @color/colorHeaderBackgroundDatePicker
as the header background while the TimePicker
will continue using the default accent color: @color/colorAccent
.
I have revised my styles. Thanks for help.
But I get still the default color: teal ...and not my own primary color blue or accent color pink.
This the code (from your example) I'm using:
// SublimePicker
SublimePickerFragment pickerFrag = new SublimePickerFragment();
pickerFrag.setCallback(mFragmentCallback);
// Options
SublimeOptions options = new SublimeOptions();
int displayOptions = 0;
displayOptions |= SublimeOptions.ACTIVATE_DATE_PICKER;
options.setDisplayOptions(displayOptions);
options.setPickerToShow(SublimeOptions.Picker.DATE_PICKER);
Pair<Boolean, SublimeOptions> optionsPair = new Pair<>(displayOptions != 0 ? Boolean.TRUE : Boolean.FALSE, options);
// Valid options
Bundle bundle = new Bundle();
bundle.putParcelable("SUBLIME_OPTIONS", optionsPair.second);
pickerFrag.setArguments(bundle);
pickerFrag.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
// pickerFrag.show(getActivity().getSupportFragmentManager(), "SUBLIME_PICKER");
pickerFrag.show(getActivity().getFragmentManager(), "SUBLIME_PICKER");
And I also use your SublimePickerFragment.java
Only one thing I had to change: I can't use Support Lib - because of a bug from Google: https://code.google.com/p/android/issues/detail?id=175086#c9
Thanks for pointing to that bug report - I wasn't aware of this issue. Is your project hosted? Or is there any other way that I can look at your project?
Meanwhile, can you try addressing the attr headerBackground
directly like this:
<style name="MySublimePickerStyle" parent="SublimePickerStyleLight">
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<!-- Change DatePicker's style -->
<item name="spDatePickerStyle">@style/MyDatePickerStyle</item>
</style>
<!-- `MyDatePickerStyle` inherits from `SublimeDatePickerStyle`. So, we don't
have to define all of the attributes used by DatePicker. We only change the one
we want to. -->
<style name="MyDatePickerStyle" parent="SublimeDatePickerStyle">
<item name="headerBackground">@color/colorAccent</item>
</style>
This should change the date picker's header background to @color/colorAccent
.
SublimePicker
relies heavily on the support libraries. So, the issue might be on that side.
Simplified code:
// SublimePicker
SublimePickerFragment pickerFrag = new SublimePickerFragment();
pickerFrag.setCallback(mFragmentCallback);
// Options
SublimeOptions options = new SublimeOptions();
options.setDisplayOptions(SublimeOptions.ACTIVATE_DATE_PICKER);
options.setPickerToShow(SublimeOptions.Picker.DATE_PICKER);
// Valid options
Bundle bundle = new Bundle();
bundle.putParcelable("SUBLIME_OPTIONS", options);
pickerFrag.setArguments(bundle);
pickerFrag.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
pickerFrag.show(getActivity().getFragmentManager(), "SUBLIME_PICKER");
I have added the headerBackground=colorAccent in styles.xml - like you wrote. Sorry - not working, still teal SublimeDatePicker.
Maybe it's the support-lib...
Code isn't hosted. Can I check something? Maybe you could exclude the support libs and try it - or Google will fix the bug hopefully in the near future!
Does the picker switch to the dark version if you use:
<style name="MySublimePickerStyle" parent="SublimePickerStyleDark">
Nothing changed. :-(
Then the style definition is not wired properly. Let's talk here: http://www.twiddla.com/2195039.
Sorry - I haven't had more time yesterday. Do you have any further idea? Tested also without support libs?
I'm still interested to use my own colors.
@vikramkakkar I found something in my styles and now it's running!
But I have 2 suggestions: 1) Header-color of date picker (also time picker) in primary and primary dark color 2) selection and button text color in accent color So the picker will look like the app.
@Rainer-Lang That's great!
If at all possible, please post the changes you had to make for SublimePicker to start behaving. I am certain that your contribution will be valuable to future users.
1) By default, the header-background color is the same as the specified accent color. Are you suggesting this color should be colorPrimary
/colorPrimaryDark
?
2) These are again taken from the accent color by default. If your defined style does not produce this, I am willing to take a look at it to determine why.
I had a mistake in my styles-v21.xml so my styles.xml isn't used for v21. Corrected and all worked.
1) Yes I know about the accentColor - but my accent color looks not good on such a big area. So I want to use my colorPrimary and colorPimaryDark instead. Yes that's what I suggest. "use primary and primarydark instead of accent color"
2) Accent color is working fine but looks for my accent color ugly.
I have overwritten the styles: spDatePickerStyle
and spTimePickerStyle
.
So my primary color is now in the header of the pickers - instead of my "ugly" (looks ugly on big areas) accent color.
If someone needs this, for me just working if i overwrite with this key ("spHeaderBackground") instead of "headerBackground"
Example:
<style name="MyDatePickerStyle" parent="SublimeDatePickerStyle">
<item name=""spHeaderBackground">@color/colorPrimary</item>
</style>
Maybe I'm doing something wrong. Need help.