Fragment should indicate preferenceTheme in onCreate topic

I am trying to find out why I am getting this error:

java.lang.IllegalStateException: Must specify preferenceTheme in theme at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:210) at android.support.v4.app.Fragment.performCreate(Fragment.java:2177) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager 

When trying to run my PreferenceFragmentCompat This is the above class code:

 public class SettingsFragment extends PreferenceFragmentCompat { public SettingsFragment() { // Required empty public constructor } public static SettingsFragment newInstance() { SettingsFragment fragment = new SettingsFragment(); return fragment; } @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.settings_preferences, rootKey); } } 

This is an activity manifest declaration showing a snippet

 <activity android:name=".active_minutes_screen.view.ActiveMinutesActivity" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> 

Code that shows a snippet in the above MainActivity

 FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, HistoryFragment.newInstance()); ft.commit(); 

Theme that I apply through MainActivity

 <style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay</item> </style> 
+5
source share
1 answer

Thanks to the solution @Panther suggested. All I had to do was add this line <item name="preferenceTheme">@style/PreferenceThemeOverlay</item> to my application theme, and not just to the individual activity topic, which shows my PreferenceFragment as follows:

 <!-- 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> 
+23
source

Source: https://habr.com/ru/post/1265404/


All Articles