package com.afollestad.materialdialogssample;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
@SuppressLint("NewApi")
public class PreferenceActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preference_activity_custom);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getFragmentManager().findFragmentById(R.id.content_frame) == null) {
getFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new SettingsFragment())
.commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}