У меня есть главное активити в котором есть navigation drawer:public class MainActivity extends ActionBarActivity {
private String[] mScreenTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mScreenTitles = getResources().getStringArray(R.array.screen_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.drawer_list);
mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.nav_draw, mScreenTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// Àêòèâèðóåì êíîïêó Home â ïàíåëè Action Bar:
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
)
{
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mDrawerTitle);
supportInvalidateOptionsMenu();
}
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
public void Click88(View view) {
setContentView(R.layout.russia);
}
public void Click120(View view) {
setContentView(R.layout.piter);
}
public void Click3(View view) {
setContentView(R.layout.prigo);
}
public void Click4(View view) {
setContentView(R.layout.sochi);
}
public void Click(View view) {
setContentView(R.layout.so_bul);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Íàñòðàèâàåì äåéñòâèå êíîïêè ïîèñêà:
switch(item.getItemId()) {
case R.id.action_search:
// Ïîêàçûâàåì Toast ñîîáùåíèå î ïîèñêå:
Toast.makeText(this, R.string.action_search, Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_search).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
// Íàñòðàèâàåì ñëóøàòåëÿ íàæàòèé ïî ïóíêòàì ìåíþ ñïèñêà â Navigation Drawer:
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment = new ScreenOne();
break;
case 1:
fragment = new ScreenTwo();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_for_drawer, fragment).commit();
mDrawerList.setItemChecked(position, true);
setTitle(mScreenTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e(this.getClass().getName(), "Ïðîèçîøëà îøèáêà!");
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
В другие фрагменты я добавил:public class S extends Fragment {
public S() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.s, container,
false);
return rootView;
}
}
Но navigation drawer работает только в главных фрагментах.То-есть которые включаются при нажатии на боковом меню.Как мне сделать чтобы шторка работала во всех фрагментах?Её видно во всех фрагментах.Но она не выдвигается.