Android app dev: Add ActionBar to Preference Activity

When I converted an activity into PreferenceActivity, I noticed that its ActionBar disappeared. I’ll show you how I brought the ActionBar back to my PreferenceActivity.

In this guide I will assume that the name of the file that contains your is SettingsActivity.java, and that the view assigned to your SettingsActivity.java is named .

First, create settings_toolbar.xml under /app/src/main/res/layout/ and place the following code into it:

Then add the following overridden method to SettingsActivity.java:

The Java method programmatically creates a Toolbar object from the XML toolbar at settings_toolbar.xml.

Reference(s): Creating a Preference Screen with support (v21) Toolbar

Catzie

A Filipino who is a mobile & web developer on weekdays, and a baker on weekends. When I have time to spare, I blog, play video games, watch series (usually anime), cook dishes, draw, or spend a little time with pets. When I have the rare luxury of time, I get to travel and record song covers too! Follow on Twitter: @catzie

Leave a Reply

Your email address will not be published. Required fields are marked *