1
I created a layout (preferences.xml) in the res/xml directory based on Preferencescreen.
I implemented a class derived from Preferencesfragmentcompat
public class PrefsFragment extends PreferenceFragmentCompat
{
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
}
}
I implemented Activity of preferences
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 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?
You declared your Activity in Manifest.xml?
– viana
I declared! It seems to me that when using a layout with <Preferencescreen> I have to declare a different theme, I just don’t know how.
– Edson Santos
What is the minSdkVersion?
– ramaral
minSdkVersion 16
– Edson Santos