有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android导航抽屉,带有菜单图标而非后退按钮

我开始学习安卓,当我创建应用程序时,我选择了导航抽屉模板,问题是:

1)即使我在主页上,也会显示“后退”按钮,并打开菜单

2)我希望在每个页面上都有一个菜单图标,并让硬件后退按钮处理意图历史

所以基本上我想知道如何将后退按钮图标更改为菜单图标

代码:(onCreateOptions菜单)

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

我可以显示/隐藏后退按钮,但我不知道它在哪里调用图标本身

抱歉,如果这是一个愚蠢的问题,但我没有找到很好的答案(在下面的链接:https://developer.安卓.com/training/implementing-navigation/nav-drawer.html


共 (1) 个答案

  1. # 1 楼答案

    在这里,你会发现一个方法,我在我的actionBar上做了一些定制,尝试使用其中的一些:),你还需要创建自己的定制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) {
    
            }
        });
    }