kizitonwose / colorpreference

A custom preference item for easy implementation of a color picker in Android's preference screen.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ColorPreferenceCompat does not work with target_sdk 29

ArLabDev opened this issue · comments

Just opened the PreferenceFragmentCompat. while executing ColorPreferenceCompat.onAttached() method, the (Activity) cast fails.

Activity activity = (Activity)context.getBaseContext();

in the tested case:

context IS an Activity
context.getBaseContext() returns a ContextThemeWrapper

with target_sdk 28, the same code works correctly.

Used Preference Library:
androidx.preference:preference:1.1.1

pref.xml

<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                                      xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.preference.PreferenceCategory
        android:title="Title">
        <com.kizitonwose.colorpreferencecompat.ColorPreferenceCompat
            android:key="label_color"
            android:title="@string/labelcolor"
            android:defaultValue="@android:color/white" />
</androidx.preference.PreferenceScreen>

tested on Android 11 and Android 10

Tested with com.github.kizitonwose.colorpreference:support:1.0.2
com.github.kizitonwose.colorpreference:support:1.1.0 works

Sorry

Somehow, compiling either com.github.kizitonwose.colorpreference:support:1.1.0 or com.github.kizitonwose.colorpreference:core:1.1.0 in gradle results in an error

compileSdkVersion 29
buildToolsVersion "30.0.2"
minSdkVersion 23
targetSdkVersion 29