Android: How to navigate back from preference subscreen via action bar in xml?
Asked Answered
M

1

6

I have a modern SettingsActivity using PreferenceFragement. I defined its layout completely in XML. In my setting I have a preference subscreen. By clicking on it a new PreferenceScreen is shown.

As it seems I can only navigate back to the main settings screen by using the back button. Is there a way to enable navigation via ActionBar in the subscreen? I'd prefer enabling it via XML.

Thanks in advance, kaolick

EDIT:

I want the same on the right side like on the left side:

enter image description here

Here is the according code snippet from Google:

<PreferenceScreen  xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- opens a subscreen of settings -->
    <PreferenceScreen
        android:key="button_voicemail_category_key"
        android:title="@string/voicemail"
        android:persistent="false">
        <ListPreference
            android:key="button_voicemail_provider_key"
            android:title="@string/voicemail_provider" ... />
        <!-- opens another nested subscreen -->
        <PreferenceScreen
            android:key="button_voicemail_setting_key"
            android:title="@string/voicemail_settings"
            android:persistent="false">
            ...
        </PreferenceScreen>
        <RingtonePreference
            android:key="button_voicemail_ringtone_key"
            android:title="@string/voicemail_ringtone_title"
            android:ringtoneType="notification" ... />
        ...
    </PreferenceScreen>
    ...
</PreferenceScreen>
Malaguena answered 14/7, 2013 at 13:2 Comment(6)
Do you still have this problem? I know to solve it.Masque
@Masque Yes, I do. I'd be glad for your solution.Malaguena
Did you ever found a solution for this problem? I'm facing the same problem right now ;)Callum
No, I'm sorry. Unfortunately @Masque didn't answer.Malaguena
check this answer: #18155536Odiliaodille
@kaolick: I would like to know the solution for thi issue. I'm a little stuck right now.Trophoplasm
S
1

First add getActionBar().setDisplayHomeAsUpEnabled(true); in onCreate().

Then try:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(android.R.id.home ==  item.getItemId() ){
        //  try one of these:

        // dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));

        // getFragmentManager().popBackStack();

        // finish();

        return true;
    }

    return super.onOptionsItemSelected(item);

}
Scotfree answered 14/7, 2013 at 13:18 Comment(1)
I tried it but this is not working. As I said before I already have navigation in the Actionbar in my SettingsActivity. I need it in my subscreen (see picture above).Malaguena

© 2022 - 2024 — McMap. All rights reserved.