Java tutorial
/** * Copyright (c) 2016 Affectiva Inc. * See the file license.txt for copying permission. */ package com.affectiva.affdexme; import android.app.ActionBar; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.support.v4.content.ContextCompat; import android.view.MenuItem; import java.util.List; //Activity which works with standard Android Preferences framework to display the preference headers. public class SettingsActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedBundleInstance) { super.onCreate(savedBundleInstance); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setIcon(new ColorDrawable( ContextCompat.getColor(getApplicationContext(), R.color.transparent_overlay))); } } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: this.onBackPressed(); return true; } return super.onOptionsItemSelected(item); } //Populate the activity with the top-level headers. @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preference_headers, target); } //Boilerplate method, required by Android API @Override protected boolean isValidFragment(String fragmentName) { return SettingsFragment.class.getName().equals(fragmentName) || MetricSelectionFragment.class.getName().equals(fragmentName); } //This fragment shows the preferences for the first header. public static class SettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.settings_preferences); } } }