After I upgraded to the Support Library v21 my ActionBar in my PreferenceActivity
is gone.
Did I miss some attributes in my theme to activate it again? I had some similar trouble with a black ActionBar.
I also tried to add it a little hackish by adding a Toolbar
to the root layout, but that did not work as expected.
Please find the GitHub Repo: Here
Very Similar to your own code but added xml to allow for set title:
Continuing to use
PreferenceActivity
:settings_toolbar.xml :
SettingsActivity.java :
Result :
UPDATE (Gingerbread Compatibility) :
As pointed out here, Gingerbread Devices are returning NullPointerException on this line:
FIX:
SettingsActivity.java :
Any issues with the above let me know!
UPDATE 2: TINTING WORKAROUND
As pointed out in many dev notes
PreferenceActivity
does not support tinting of elements, however by utilising a few internal classes you CAN achieve this. That is until these classes are removed. (Works using appCompat support-v7 v21.0.3).Add the following imports:
Then override the
onCreateView
method:Result:
AppCompat 22.1
AppCompat 22.1 introduced new tinted elements, meaning that there is no longer a need to utilise the internal classes to achieve the same effect as the last update. Instead follow this (still overriding
onCreateView
):NESTED PREFERENCE SCREENS
A lot of people are experiencing issues with including the Toolbar in nested
<PreferenceScreen />
s however, I have found a solution!! - After a lot of trial and error!Add the following to your
SettingsActivity
:The reason that
PreferenceScreen
's are such a pain is because they are based as a wrapper dialog, so we need to capture the dialog layout to add the toolbar to it.Toolbar Shadow
By design importing the
Toolbar
does not allow for elevation and shadowing in pre-v21 devices, so if you would like to have elevation on yourToolbar
you need to wrap it in aAppBarLayout
:`settings_toolbar.xml :
Not forgetting to add the add the Design Support library as a dependency in
build.gradle
file:Android 6.0
I have investigated the reported overlapping issue and I cannot reproduce the issue.
The full code in use as above produces the following:
If I am missing something please let me know via this repo and I will investigate.