android - 通过单击应用程序图标打开导航抽屉? [英] android - open navigation drawer by clicking the app icon?

查看:25
本文介绍了android - 通过单击应用程序图标打开导航抽屉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用导航抽屉(您通过从屏幕左侧滑动打开的导航类型).现在,通常你也可以通过点击应用程序图标来打开它,当我查看它时,我发现一大堆代码可以添加到你的活动中.而且只是一个简单的按钮.我想那不正是我要找的吗?如果一个按钮真的需要这么多代码,让代码更清晰的最好方法是什么?谢谢你,也很抱歉成为这样的安卓新手.

I use a navigation drawer in my app (the type of navigation that you open by sliding from the left side of the screen). Now, usually you can also open it by tapping the app icon, and when I looked it up, I found a whole bunch of code to add to your activity. And just for a simple button. I suppose thats not exactly what I am looking for? And if it really needs to be so much code for a single button, what is the best way to make the code more clear? Thank you, and sorry for being such an android newb.

推荐答案

我也遇到了这个问题,假设您已经按照@Kernald 的建议有一个 ActionBarDrawerToggle,您还需要将以下内容添加到您的 Activity:

I ran into this issue also, assuming you already have an ActionBarDrawerToggle as @Kernald suggested, you need to add the following also to your Activity:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }
    // Handle your other action bar items...

    return super.onOptionsItemSelected(item);
}

这让我们切换手柄按下操作栏上的图标按钮,导致抽屉滑出.

This let's the toggle handle the icon button press on the ActionBar, causing the Drawer to slide out.

这篇关于android - 通过单击应用程序图标打开导航抽屉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆