title: How to use PreferenceScreen of Androidx
body: <p>My problem is that I wanted to <em>add a PreferenceScreen to my Application</em>, but I can't use it and I don't know why.</p>
  
  <p>I implemented the library <code>androidx.preference:preference:1.1.0-rc01</code>. Then I wanted to add the PreferenceScreen to my XML-layout and it doesn't suggest any suggestion.</p>
  
  <p>Next, I copied the XML-Code from Android-Developers into my XML-layout and compiled it, but by starting the activity it breaks with the error: <code>java.lang.ClassCastException: class androidx.preference.PreferenceScreen cannot be cast to android.view.View</code></p>
  
  <p>Can somebody help me to use the <code>androidx.preference.PreferenceScreen</code> correctly?</p>
  
  <p>My Layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.preference.PreferenceScreen  xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="match_parent"
      android:layout_width="match_parent"&gt;
      &lt;androidx.preference.SwitchPreference
          android:defaultValue="true"
          android:key="example_switch"
          android:summary="Turn this option on or off"
          android:title="Settings option" /&gt;
  &lt;/androidx.preference.PreferenceScreen&gt;
  </code></pre>