Added back button to preferences ActionBar for honeycomb and later.

This commit is contained in:
Felix Ableitner 2014-05-01 20:34:54 +02:00
parent 57f5d65e30
commit 38815cae34
2 changed files with 27 additions and 1 deletions

View file

@ -43,7 +43,13 @@
<activity
android:name=".gui.PreferencesActivity"
android:label="@string/settings_title" />
android:label="@string/settings_title" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.github.nutomic.controldlna.gui.MainActivity" />
</activity>
<service android:name="org.teleal.cling.android.AndroidUpnpServiceImpl" />

View file

@ -29,10 +29,13 @@ package com.github.nutomic.controldlna.gui;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import com.github.nutomic.controldlna.R;
@ -46,11 +49,28 @@ public class PreferencesActivity extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// There is currently no way to get ActionBar in PreferenceActivity on pre-honeycomb with
// compatibility library, so we'll have to do a version check.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
addPreferencesFromResource(R.xml.preferences);
final PreferenceScreen screen = getPreferenceScreen();
mContactDev = screen.findPreference(KEY_CONTACT_DEV);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {