简体   繁体   中英

Android Studio rendering problems: Preferences

Here is the code of my preferences.xml file:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
    <CheckBoxPreference
        android:key = "test"
        android:title = "Test"
        android:summary = "Yes It WORKED"
        android:defaultValue="true"
        />

</PreferenceScreen>

android studios renderer gives me the following error message:

The following classes could not be found:
    -CheckBoxPreference(Fix build path)
    -PreferenceScreen(Fix build path)

Also it gave me errors when I didn't put in:

android:layout_height="match_parent"
android:layout_width="match_parent">

although Google itself ( http://developer.android.com/guide/topics/ui/settings.html ) doesn't say a word about this. (Also they show an action bar when running the code all I get is a checkbox preference on the very top of the screen)

Create a xml folder inside res and move your .xml file (Ex:preferences.xml)inside it.

在此处输入图片说明

The interface of a PreferenceFragment must not be defined as a layout resource file, but as an XML resource file. This is explained in the link you gave but somehow hidden: http://developer.android.com/guide/topics/ui/settings.html#Fragment

If you follow this approach, Android Studio's rendering works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM