fixed settings title change on frag transaction

This commit is contained in:
danijoo
2015-12-31 19:52:38 +01:00
parent 024f7a00b3
commit 8fd7d750fe
4 changed files with 17 additions and 7 deletions

View File

@@ -2,7 +2,6 @@ package net.headlezz.notificationlogger;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
public class BlacklistFragment extends Fragment {
@@ -10,6 +9,5 @@ public class BlacklistFragment extends Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((AppCompatActivity) activity).getSupportActionBar().setTitle("Blacklist");
}
}

View File

@@ -26,10 +26,7 @@ public class PreferenceActivity extends AppCompatActivity implements PreferenceF
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if(getSupportFragmentManager().findFragmentById(R.id.fragment_holder) == null) {
PreferenceFragment pf = new PreferenceFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_holder, pf)
.commit();
showSettingsScreen();
}
}
@@ -54,5 +51,20 @@ public class PreferenceActivity extends AppCompatActivity implements PreferenceF
.replace(R.id.fragment_holder, new BlacklistFragment())
.addToBackStack("blacklist")
.commit();
getSupportActionBar().setTitle(getString(R.string.title_blacklist));
}
public void showSettingsScreen() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_holder, new PreferenceFragment())
.commit();
getSupportActionBar().setTitle(getString(R.string.title_settings));
}
@Override
public void onBackPressed() {
if(getSupportFragmentManager().getBackStackEntryCount() > 0)
getSupportActionBar().setTitle(getString(R.string.title_settings));
super.onBackPressed();
}
}

View File

@@ -44,7 +44,6 @@ public class PreferenceFragment extends PreferenceFragmentCompat implements Pref
public void onAttach(Activity activity) {
super.onAttach(activity);
mCallbacks = (PreferenceCallbacks) activity;
((AppCompatActivity) activity).getSupportActionBar().setTitle("Settings");
}
@Override

View File

@@ -15,4 +15,5 @@
<string name="pref_about_title">About</string>
<string name="fab_cd_create_notification">FAB: Create notification</string>
<string name="title_create_notification">Create notification</string>
<string name="title_blacklist">Blacklist</string>
</resources>