vikramkakkar / SublimePicker

A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.
Apache License 2.0
2.31k stars 407 forks source link

Own style doesn't work for me (colors).... #6

Closed Rainer-Lang closed 8 years ago

Rainer-Lang commented 9 years ago

Maybe I'm doing something wrong. Need help.

vikramkakkar commented 9 years ago

Can you post your project's styles.xml?

Rainer-Lang commented 9 years ago

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>
vikramkakkar commented 9 years ago

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.

Rainer-Lang commented 9 years ago

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

vikramkakkar commented 9 years ago

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");
Rainer-Lang commented 9 years ago

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!

vikramkakkar commented 9 years ago

Does the picker switch to the dark version if you use:

<style name="MySublimePickerStyle" parent="SublimePickerStyleDark">
Rainer-Lang commented 9 years ago

Nothing changed. :-(

vikramkakkar commented 9 years ago

Then the style definition is not wired properly. Let's talk here: http://www.twiddla.com/2195039.

Rainer-Lang commented 9 years ago

Sorry - I haven't had more time yesterday. Do you have any further idea? Tested also without support libs?

Rainer-Lang commented 8 years ago

I'm still interested to use my own colors.

Rainer-Lang commented 8 years ago

@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.

vikramkakkar commented 8 years ago

@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.

Rainer-Lang commented 8 years ago

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.

Rainer-Lang commented 8 years ago

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.

TechnoTrancer commented 8 years ago

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>