Mika Mika - 11 days ago 5
Android Question

Does `PreferenceScreen` need height and width?

I got the following code from the android documentation

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="pref_sync"
android:title="@string/pref_sync"
android:summary="@string/pref_sync_summ"
android:defaultValue="true" />
<ListPreference
android:dependency="pref_sync"
android:key="pref_syncConnectionType"
android:title="@string/pref_syncConnectionType"
android:dialogTitle="@string/pref_syncConnectionType"
android:entries="@array/pref_syncConnectionTypes_entries"
android:entryValues="@array/pref_syncConnectionTypes_values"
android:defaultValue="@string/pref_syncConnectionTypes_default" />
</PreferenceScreen>


Android studio is giving me an error saying I am missing Height and Width on the
PreferenceScreen
tag. It's easy enough to fix but I can't believe the doc would have invalid code so I am curious if I am doing something wrong and I am missing a setting somewhere.

Answer

Probably a studio bug recognizing PreferenceScreen as layouts if you misplaced it in res/layout/ folder.

Your preference xml should be res/xml/ folder.