抽屉指示灯不显示

时间:2014-11-07 15:57:35

标签: android drawerlayout indicator

我无法显示抽屉指示器。目前我没有任何东西或“<”根据actionBar设置,在屏幕的左上角。但我想要Nagivation抽屉的抽屉指示器。

我用:

  • v4.widget.DrawerLayout
  • v7.app.ActionBarDrawerToggle
  • 但是android.app.ActionBar(不是支持7)。

以下是代码片段:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    actionBar.setDisplayHomeAsUpEnabled(true); 
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    //I tried all combinations unsuccessfully
    ....
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerLV = (ListView) findViewById(R.id.left_drawer);
    drawer_Linearlayout = (LinearLayout) findViewById(R.id.drawer_Linearlayout);

    drawerLV.setAdapter(new ArrayAdapter<String>(
            this,
            R.layout.layout_main_drawer_list_item,
            mDrawerItems));

    drawerLV.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });

    drawerToggle = new ActionBarDrawerToggle(this, drawer, R.string.drawer_open,R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View view) {
            actionBar.setTitle(mTitle);
    }
        @Override
        public void onDrawerOpened(View drawerView) {
            actionBar.setTitle(mDrawerTitle);
        }
    };
    drawerToggle.setDrawerIndicatorEnabled(true);
    drawer.setDrawerListener(drawerToggle);
}

3 个答案:

答案 0 :(得分:1)

我最终解决了我的问题。 我忘了在我的Acticity中添加以下回调:

protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    drawerToggle.syncState();
}

顺便说一下,当导航抽屉打开或关闭时,v7.app.ActionBarDrawerToggle的Lollipop升级会增加一个很好的效果。我推荐它。

答案 1 :(得分:0)

我认为您还必须在android.R.id.home中指定onOptionsItemSelected以使后退按钮可见:

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            //the onClick for your back button
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

您只需要使用actionBar.setDisplayHomeAsUpEnabled(true);

更新:

只是快速谷歌搜索,看看这个:

Display back button on action bar

试试我的回答。我认为它会解决你的问题。

答案 2 :(得分:0)

对不起我之前的回答,我误解了。认为这就是你需要的:

mDrawerToggle = new ActionBarDrawerToggle(
        this,                             
        mDrawerLayout,                 
        R.drawable.ic_drawer, /* The image drawable you're missing */          
        R.string.navigation_drawer_open,  
        R.string.navigation_drawer_close  

图像是自定义的,也称为汉堡包。