I have implemented DoneBar (two buttons in actionbar) in PreferenceActivity
as provided in v20 sdk samples, but after updating SDK and AppCompat to version 21 m
Issue resolved by doing this, your styles xml should looks like this.
res/values/style.xml
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowActionBar">true</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
res/values-v11/style.xml
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
res/values-v14/style.xml
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
getActionBar()
returns null in API 5.0 when i use Activity
or FragmentActivity
.I solved this extendig to ActionBarActivity
public class MainActivity extends ActionBarActivity {
You must use getSupportActionBar()
when you are using ActionBarActivity
(appcompat-v7
).
I managed to fix this issue by specifying custom theme for my settings activity,
<style name="SettingsTheme" parent="style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>
and : android:theme="@style/SettingsTheme"
in manifest for activity
actionbar is again showing on KITKAT and LOLIPOP and (have not tested it) back to api v11. I tested it and it works (with no actionbar as expected) on api 10.
From debugging on lolipop, FEATURE_NO_TITLE
was being set in PhoneWindow.java:3243
:
if (a.getBoolean(R.styleable.Window_windowNoTitle, false)) {
requestFeature(FEATURE_NO_TITLE);
which removes FEATURE_ACTION_BAR
[edit]
but this action bar is not from material theme, so still its not perfect
[edit2]
I gave up with Headers, now I am using PreferenceFragment backport from github. Now all my actionbars are the same after upgrade to appcompact 21.
as xXx requested I am providing example how I done:
public class SettingsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
// use action bar here
ActionBar actionBar = getSupportActionBar();
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
addPreferencesFromResource(R.xml.pref_settings);
}
}
}