我正在尝试将新的 DrawerLayout 用于列表。问题是虽然我设置了抽屉监听器,但操作栏上的指示器仍然是箭头图标,而不是我打算绘制的 3 行图标。以下是 OnCreate 函数:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
// Swiping Pager set up
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// Sliding Drawer set up
mHabitContract = new HabitsContract(this);
mDrawerLayout = (DrawerLayout) findViewById(R.id.front_page_layout);
mDrawerList = (ListView) findViewById(R.id.habit_list);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerList.setAdapter(new HabitAdapter(mHabitContract.GetHabitItems(), this));
// Fixme: Indicator image doesn't show up
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
//getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
//getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Action Bar set up
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
}
任何人都可以帮忙吗?
更新:我发现了问题。我按如下方式添加了 onPostCreate 函数,现在它可以工作了。
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}