0

enter image description here

I have google map on my screen and I want open SETTING page in navigation drawer with a setting button. but you can see there are an overlaps stiation. also if I pressed the back button, instead of backing map screen ,app is exiting. dont coming back the main screen.

I am using docs codes:

public static class SettingsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
    }
    ...
}

in a button click listener code is in my Activity

// Display the fragment as the main content.
    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new SettingsFragment())
            .commit();

also this is the map fragment

@Override

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(map);
        mapFragment.getMapAsync(this);

docs says:

If you're developing for Android 3.0 (API level 11) and higher, you should use a PreferenceFragment to display your list of Preference objects. You can add a PreferenceFragment to any activity—you don't need to use PreferenceActivity.

so I want to use setting with fragment I dont want to change fragment with activity

[SOLVED]

after Keerthivasan helps. the result code is this and working properly

getFragmentManager().beginTransaction()
                    .replace(android.R.id.content, new SettingsFragment())
                    .addToBackStack("map") //new added
                    .commit();

also in PreferenceFragment added

   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        view.setBackgroundColor(Color.WHITE);

        return view;
    }
mehmet
  • 1,558
  • 5
  • 30
  • 41
  • The statements you have explained is not at all clear... May be you should go back and edit your explanation – Sreehari May 08 '17 at 09:19
  • Simply, there are 2 problems. one of them I've a map fragment and I want open SETTING fragment on it. but it looks at screentshoot (overlaps). also in setting screen if I press back, program exiting. but it should go to map screen – mehmet May 08 '17 at 09:42

1 Answers1

2

The problem is, added fragment taking background as transparent, so set background to fragment layout. It will solve the problem :-) Official Docs For Back Stack Manager.. you can find N - number of examples in Stackoverflow itself.

Keerthivasan
  • 1,651
  • 1
  • 21
  • 47