gregkorossy / Android-Support-Preference-V7-Fix

Android androidx.preference support library has some issues, this lib tries to fix them.
https://discord.gg/87NVsSK
Apache License 2.0
497 stars 46 forks source link

Blank Preferences Screen #128

Closed phillwiggins closed 6 years ago

phillwiggins commented 6 years ago

For some reason I being shown a blank preferences screen.

The fragment is loading correctly as I can set the background programatically to a different colour, however, nothing else is shown.

<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">

class FragmentSettings : PreferenceFragmentCompatDividers() {

override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String) {
    setPreferencesFromResource(R.xml.preferences, rootKey)
    // additional setup
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
    try {
        val v = super.onCreateView(inflater, container, savedInstanceState)!!
        context?.let { v.setBackgroundColor(ContextCompat.getColor(it, R.color.background)) }
        v.isClickable = true
        return v
    } finally {
        setDividerPreferences(DIVIDER_PADDING_CHILD or DIVIDER_CATEGORY_AFTER_LAST or DIVIDER_CATEGORY_BETWEEN)
    }
}
}

<!-- Base application theme. -->
<style name="AppTheme" parent="@style/PreferenceFixTheme.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
gregkorossy commented 6 years ago

Check the logcat, you'll probably see a caught exception there (it's getting caught in the PreferenceFragmentCompat's onCreate(...) as of now but I'll remove the try...catch block).

phillwiggins commented 6 years ago

Ahh yes, I missed this somehow, I'm getting:-

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter rootKey 12-05 19:31:53.816 10344-10344/ W/System.err: at FragmentSettings.onCreatePreferencesFix(FragmentSettings.kt:0)

gregkorossy commented 6 years ago

The rootKey param is not annotated with @NonNull, so it can be null. You should update your implementation so that it is reflected (mind the ? after String in the params):

override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
    setPreferencesFromResource(R.xml.preferences, rootKey)
    // additional setup
}
gregkorossy commented 6 years ago

Did it solve your problem?

phillwiggins commented 6 years ago

Apologies for the late response. Yes. My issue was unrelated and was the mutable variable issue.

On 10 Dec 2017 12:37, "Gergely Kőrössy" notifications@github.com wrote:

Did it solve your problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Gericop/Android-Support-Preference-V7-Fix/issues/128#issuecomment-350545422, or mute the thread https://github.com/notifications/unsubscribe-auth/AHgn3vtjMQku37OWd-2dPX0MB4ewcrD6ks5s-9CdgaJpZM4Q2wyW .