Zohaib Ghafoor Baloch
Zohaib Ghafoor Baloch

Reputation: 63

Android PreferenceFragmentCompat custom layout list_container error

I want to add custom layout with Preferences List. but it gives me this error.

Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class

Layout:

<FrameLayout
    android:id="@+id/list_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Styles:

<style name="BestMainTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorControlNormal">@color/white</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/windowBackground</item>
    <item name="preferenceTheme">@style/BestAppSettingsTheme</item>
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/darker_gray</item>
    <item name="android:textColorHint">@android:color/darker_gray</item>
</style>

<style name="BestAppSettingsTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
    <item name="android:layout">@layout/fragment_preferences</item>
</style>

Code:

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

    setPreferencesFromResource(R.xml.preferences, rootKey);

}

Upvotes: 0

Views: 1373

Answers (1)

Gustavo Pagani
Gustavo Pagani

Reputation: 6988

If you are using Support Preference version 24 or later, Google has changed the needed id from R.id.list_container to android.R.id.list_container.

So just change your layout file to:

<FrameLayout
    android:id="@android:id/list_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Upvotes: 2

Related Questions