gpt4 book ai didi

Android DrawerLayout 不显示正确的指示器图标

转载 作者:IT王子 更新时间:2023-10-28 23:29:22 26 4
gpt4 key购买 nike

我正在尝试将新的 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();
}

最佳答案

您需要 syncState()onPostCreate()

调用您的 ActionBarDrawerToggle 对象
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}

关于Android DrawerLayout 不显示正确的指示器图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17825629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com