简体   繁体   English

Android-带菜单图标而不是后退按钮的导航抽屉

[英]Android - Navigation drawer with menu icon instead of back button

I'm starting learning android and when I created my app I chose the Navigation Drawer template and here is the problem: 我开始学习android,当我创建应用时,我选择了Navigation Drawer模板,这就是问题所在:

1) Even though I'm at the homepage the back button is displayed, and it opens the menu 1)即使我在主页上,也会显示返回按钮,并打开菜单

2) I'd like to have a menu icon in every single page and let the hardware back button handle the intent history 2)我想在每个页面中都有一个菜单图标,然后让硬件后退按钮处理意图历史记录

So basically I'd like to know how to change back button icon to menu icon. 因此,基本上我想知道如何将“后退”按钮图标更改为菜单图标。

code: (onCreateOptionsMenu) 代码:(onCreateOptionsMenu)

ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

I can show/hide the back button but I can't figure out where it's calling the icon itself 我可以显示/隐藏后退按钮,但无法弄清楚它在哪里调用图标本身

Sorry if it's a silly question but I didn't find good answers to this (on ly this link: https://developer.android.com/training/implementing-navigation/nav-drawer.html ) 抱歉,这是一个愚蠢的问题,但我没有对此找到好的答案(仅此链接: https : //developer.android.com/training/implementing-navigation/nav-drawer.html

Here you will find a method where i do some customization over my actionBar try to use some of it :) , also you will need to make your own custom action bar xml file 在这里,您将找到一种方法,在该方法中我对actionBar进行一些自定义,尝试使用其中的一些方法:),而且您还需要制作自己的自定义操作栏xml文件

    private void setCustomActionBar() {

    ActionBar mActionBar = this.getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);

    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.custom_main_actionbar, null);

    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);

    actionBarTitle = (TextView) mCustomView.findViewById(R.id.action_bar_title_tv);
    actionBarHomeBtn = (ImageView) mCustomView.findViewById(R.id.action_bar_app_icon);
    actionBarSyncBtn = (ImageView) mCustomView.findViewById(R.id.action_bar_sync_btn);
    actionBarSearchBtn = (ImageView) mCustomView.findViewById(R.id.action_bar_search_btn);
    actionBarHomeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else {
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }
    });

    actionBarSyncBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    actionBarSearchBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM