所以,我有一个名为SlidingFragmentActivity
的Fragment活动的扩展,我将其用作我想要显示DrawerLayout的活动的基础。一切正常,直到您按下后退按钮并尝试使用主页按钮打开抽屉。什么都没发生。从挡板上滑动仍然有效。我也试过DrawerLayout.openDrawer(Gravity.LEFT);
无济于事。
使用Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
开始活动也是一样。
所有代码都是从this example复制的,所以我不明白为什么它不起作用?
以下是完整的SlidingFragmentActivity
:
public class SlidingFragmentActivity extends FragmentActivity {
public static DrawerLayout mDrawerLayout;
public static ActionBarDrawerToggle mDrawerToggle;
// Fragment manager
public FragmentManager fragmentManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sliding_menu);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
);
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
fragmentManager = getSupportFragmentManager();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return true;
}
public static void openDrawer() {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
}
我绝不是活动生命周期的专家,但我猜它与instanceState有关吗?
其他人遇到这个问题/知道如何解决它?