Android error - Must specify preferenceTheme in theme

1

I created a layout (preferences.xml) in the res / xml directory based on the PreferenceScreen.

Implemented a class derived from PreferencesFragmentCompat

public class PrefsFragment extends PreferenceFragmentCompat  
{
  @Override   
  public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);    
  }
}

Implemented the preferences activity

public class PrefsActivity extends AppCompatActivity
{

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.prefs_activity);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragContent, new PrefsFragment());
    transaction.commit();
  }

} 

When I run the activity the following error is displayed:

  

java.lang.RuntimeException: Unable to start activity   ComponentInfo {PrefsActivity}: java.lang.IllegalStateException: Must   specify preferenceTheme in theme

How do I specify the preferenceTheme ?

    
asked by anonymous 30.09.2016 / 21:08

1 answer

1

In the file res/values/styles.xml add

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

If you have not changed anything in the file generated by Android Studio, it will look like this:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

If you are using the v7 Preference Support Library I suggest replacing it with v14 Preference Support Library because in " problems " / a> with preferenceTheme .

    
03.10.2016 / 23:34