I am trying to implement a Settings screen using PreferenceFragmentCompat. My preference xml has a preference subscreen like this:
preferences.xml
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_sound_key"
android:summary="@string/pref_sound_summary"
android:title="@string/pref_sound_title" />
<PreferenceScreen android:title="Inner Screen">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_1"
android:title="@string/title_1" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_1"
android:title="@string/title_1" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_2"
android:title="@string/title_2" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_3"
android:title="@string/title_3" />
</PreferenceScreen>
</PreferenceScreen>
Now, in the app, the subscreen does not open until I implement PreferenceFragmentCompat.OnPreferenceStartScreenCallback interface in parent activity, as specified in PreferenceFragmentCompat doc.
MainActivity.java
public boolean onPreferenceStartScreen(PreferenceFragmentCompat preferenceFragmentCompat,
PreferenceScreen preferenceScreen) {
preferenceFragmentCompat.setPreferenceScreen(preferenceScreen);
return true;
}
Here's where the problem arises. On implementing the interface, the subscreen opens, but then there is no way I can find to move back to first screen.
Pressing back key closes the app.
Is there any way I can put a back arrow on app bar so that pressing it will bring the main screen back?