【问题标题】:Drawer Indicator does not show抽屉指示灯不显示
【发布时间】:2014-11-07 15:57:34
【问题描述】:

我无法显示抽屉指示器。目前,根据 actionBar 设置,我在屏幕左上角没有任何内容或“

我用:

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

这里是sn-p的代码:

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

【问题讨论】:

标签: android drawerlayout indicator


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    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

    试试我的答案。我想它会解决你的问题。

    【讨论】:

    • 谢谢,但我可以轻松获得后退按钮。我想要的是用抽屉指示器替换它。
    • @u2gilles 对不起..您在问题中这样说:“我什么都没有,或者屏幕左上角的“
    【解决方案3】:

    对不起,我之前的回答,我看错了。认为这就是您所需要的:

    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  
    

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

    【讨论】:

    • 这个参数在android.support.v7.app.ActionBarDrawerToggle中已经不存在了;并且 android.support.v4.app.ActionBarDrawerToggle 现在已经贬值了。无论如何,我也在 android.support.v4.app.ActionBarDrawerToggle 中尝试过,它也无法正常工作。
    猜你喜欢
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    相关资源
    最近更新 更多