Android的 - 开抽屉式导航栏点击应用程序图标? [英] android - open navigation drawer by clicking the app icon?

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

问题描述

我在我的应用程序(导航,你从屏幕左侧的滑开的类型)使用的导航抽屉。现在,通常你也可以打开它通过点击应用程序图标,当我看着它,我发现了一大堆code添加到您的活动。而只是一个简单的按钮。我想那不是正是我期待的?如果它真的需要这么多$ C $下一个按钮,是什么使code更清晰的最佳方法?谢谢,对不起,是这样的一个机器人福利局。

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.

推荐答案

我就遇到了这个问题还,假设你已经有一个ActionBarDrawerToggle为@Kernald建议,您还需要以下内容添加到您的活动:

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

这让我们拨动手柄上的动作条图标按钮preSS,造成抽屉滑出。

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

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

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