android - 抽屉导航图标 (ic_drawer) 未显示

标签 android icons android-actionbar navigation-drawer

我正在为我的应用实现一个抽屉式导航。现在它工作得很好,除了一个小故障。当我设置抽屉导航图标 (ic_drawer) 以替换常规的“HomeAsUp”插入符号图标时,我仍然得到箭头。抽屉导航图标不显示。我已经实现了 android 开发者网站上的所有方法。但这似乎不起作用。

下面是我的代码:

DrawerLayout mDrawerLayout;
FrameLayout leftDrawer, rightDrawer, contentFrame;
ActionBarDrawerToggle mDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    initializeViews();
}

private void initializeViews() {
    // TODO Auto-generated method stub
    mDrawerLayout = (DrawerLayout) findViewById(R.id.mDrawerLayout);
    mDrawerToggle = new ActionBarDrawerToggle(this,
            mDrawerLayout, R.drawable.ic_drawer,
            R.string.drawer_open_content_desc,
            R.string.drawer_close_content_desc);

    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    leftDrawer = (FrameLayout) findViewById(R.id.drawerLeft_frame);
    rightDrawer = (FrameLayout) findViewById(R.id.drawerRight_frame);
    contentFrame = (FrameLayout) findViewById(R.id.content_frame);
}


@Override
protected void onPostCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);
    mDrawerToggle.onConfigurationChanged(newConfig);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

最佳答案

我知道现在回答这个问题已经很晚了,但这至少会对某人有所帮助。

您可能应该添加这些代码行来显示导航图标。

@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);
}

关于android - 抽屉导航图标 (ic_drawer) 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385101/

相关文章:

android - 如何将 ActionBar 添加到已经扩展了 ListActivity 的 Activity 中?

android - 3M触摸屏,安卓4.1.2

java - 图像显示不正确

java - jlabel 上的图标获取 jlabel 的大小

android - 拆分操作栏 - 当我使用 android :showAsAction ="always" 时图标重叠

css - 字体图标在悬停时抽动

android - 上下文操作栏强制溢出

类似 twitter 示例的 Android 操作栏

android - 缺少 LableStyle 字体

java - ListView 条目在滚动时会更改其布局