Reputation: 1281
I'm trying to add a PreferenceFragment
in my application. The problem is, it's auto placed on top of my NavigationDrawer
.
public class SetPreferenceActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
navigationDrawer(); // Loads the NavigationDrawer
getFragmentManager().beginTransaction().replace(android.R.id.content,
new Settings()).commit();
}
As you can see I load the "SettingsFragment" and replace the content with it? (I'm unsure) but it places it on top of everything else.. Here's my Settings fragment.
public class Settings extends PreferenceFragment {
static final String TAG = "MAIN";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
Everything work as expected, BUT the PreferenceFragment are loaded in front, covering up the NavigationDrawer slideout, I tried calling bringToFront();
on the listview, with no luck.
A picture for reference :
Is it possible to tell the fragment to load behind the listview? I also tought about loading the fragment in a ViewPager, but I get an error that the Pager Adapter wont accept fragments of type PreferenceFragment.
Upvotes: 3
Views: 1406
Reputation: 378
I had same issue and i resolved it by replacing android.R.id.content to R.id.container.
Upvotes: 0
Reputation: 121
In addition to what adneal said (in case others have the same problem):
The Activity which calls the PreferenceFragment needs to have the setContentView()
method if you extend the Activity with your NavigationDrawer:
public class SetPreferenceActivity extends MyNavigationDrawer {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
getFragmentManager().beginTransaction().replace(R.id.drawer_frame_layout,
new Settings()).commit();
}
And the settings.xml
should only contain a FrameLayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Upvotes: 0
Reputation: 30804
Don't replace android.R.id.content
, use the the id of the FrameLayout
you have in the layout that contains your DrawerLayout
.
Upvotes: 6