androidandroid-fragmentssettingspreferencefragment

Unknown attribute class warning with FragmentContainerView


I have a SettingsFragment class that hosts a PreferenceFragment for the app settings.

In layout, I used FragmentContainerView which points to that PreferenceFragment class with the class attribute.

<androidx.fragment.app.FragmentContainerView
    class="xxxxxx.fragments.SettingsFragment$PreferenceFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Backing to normal fragment instead of FragmentContainerView the warning is gone, so it turns out that it's related to FragmentContainerView.

How can I get rid of this warning while using FragmentContainerView?


Solution

  • It should be android:name="xxxxxx.fragments.SettingsFragment$PreferenceFragment" as per FragmentContainerView documentation.

    <androidx.fragment.app.FragmentContainerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/fragment_container_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:name="xxxxxx.fragments.SettingsFragment$PreferenceFragment"
            android:tag="my_tag">
     </androidx.fragment.app.FragmentContainerView>