mehmet
mehmet

Reputation: 1588

Map fragment with Setting fragment Overlaps

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;
    }

Upvotes: 0

Views: 375

Answers (1)

Keerthivasan
Keerthivasan

Reputation: 1661

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.

Upvotes: 2

Related Questions