I have this fragment:
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.settings, rootKey);
}
}
And I want to add this Fragment to a .XML file. This is what I have tried:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"/>
<com.example.myapp.SettingsFragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"/>
</RelativeLayout>
</layout>
I can confirm that this is the correct location of the file:
com.example.myapp.SettingsFragment
However, this is not inflated, due this error:
android.view.InflateException: Binary XML file line #14 in com.example.myapp:layout/fragment_settings: Class is not a View com.example.myapp.SettingsFragment
That is pointing to:
<com.example.myapp.SettingsFragment
How to inflate this custom Fragment into my XML file?
The XML file is the layout of a Fragment and not of an activity.