Adding toolbar to Preference Activity

There are a lot of questions on StackOverflow about adding an ActionBar/Toolbar to the PreferenceActivity. However this task is quite easy in the newer versions of Android Studio.

I'm using Android Studio 1.4. When I create a new preference activity from the menu, Android Studio adds an extra abstract AppCompatPreferenceActivity class which extends PreferenceActivity. The SettingsActivity class I created from the menu extends the AppCompatPreferenceActivity class. This abstract class has a lot of useful methods that's missing in the PreferenceActivity class.

To add the toolbar, all I need to do is inflate the toolbar into the view and set it as the ActionBar by calling setSupportActionBar() or setActionBar() if you aren't using the AppCompat Toolbar.