Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors do not correspond with application theme #7

Open
kuhy opened this issue Mar 4, 2020 · 0 comments
Open

Colors do not correspond with application theme #7

kuhy opened this issue Mar 4, 2020 · 0 comments

Comments

@kuhy
Copy link

kuhy commented Mar 4, 2020

First of all, I would like to thank you for this amazing library. It is the best PickerView I found so far. There is only one problem.

When I use PickerView with dark theme, topMask and bottomMask are not set correctly. Please set those fields to value corresponding with actual theme. You will need to add something like this:

TypedValue typedValue = new TypedValue();
if (resolveAttribute(android.R.attr.windowBackground, typedValue, true)) {
    int[] gradientColors = {typedValue.data, Color.TRANSPARENT};
    topMask = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors);
    bottomMask = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, gradientColors);
}

Or make those fields public. In the meantime, I am forced to use this ugly workaround (reflection):

fun Resources.Theme.fixPickerViewsMask(vararg pickerViews: PickerView) {
    val typedValue = TypedValue()
    if (resolveAttribute(android.R.attr.windowBackground, typedValue, true)) {
        val gradientColors = intArrayOf(typedValue.data, Color.TRANSPARENT)

        val topMask = PickerView::class.java.getDeclaredField("topMask")
        topMask.isAccessible = true
        val bottomMask = PickerView::class.java.getDeclaredField("bottomMask")
        bottomMask.isAccessible = true

        for (picker in pickerViews) {
            topMask.set(picker, GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors))
            bottomMask.set(picker, GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, gradientColors))
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant