简体   繁体   English

带导航抽屉的操作栏

[英]Action Bar with navigation drawer

This is very similar to many question already posted on stackoverflow, but I still haven't found the right solution. 这与已经在stackoverflow上发布的许多问题非常相似,但是我仍然没有找到正确的解决方案。 The problem I'm facing is how to implement a custom actionbar.xml file and add a navigation drawer function to the top left icon. 我面临的问题是如何实现自定义actionbar.xml文件并将导航抽屉功能添加到左上方的图标。

I'm trying to create an action bar that looks like this with two ImageButtons on side and an ImageView as a logo in the center. 我正在尝试创建一个看起来像这样的操作栏,在侧面有两个ImageButtons,在中央有一个ImageView作为徽标。 When user presses on the left ImageButton from actionbar.xml, I would like navigation drawer coming from the left, like in this tutorial . 当用户从actionbar.xml按下左侧的ImageButton时,我希望导航抽屉从左侧进入,就像本教程一样 The last thing that troubles me, is how to put a title of pressed fragment in the center of the action bar instead of a logo. 让我困扰的最后一件事是如何在操作栏的中心放置一个按下的片段标题而不是徽标。

I've already written all xml and java files, but I just can't put the pieces together. 我已经写了所有的xml和java文件,但是我无法将各个部分放在一起。 Please help. 请帮忙。

I believe you have solution to create navigation drawer. 我相信您有创建导航抽屉的解决方案。

Now for your question HOW TO CREATE A CUSTOM ACTION BAR 现在您的问题如何创建自定义操作栏

Try like this .. 这样尝试..

    actionBar = getSupportActionBar(); // Get Action Bar reference.

        actionBar.setCustomView(R.layout.action_bar_confirm_cabs); Set your action bar view like this

        fare_ll = (TextView) actionBar.getCustomView().findViewById(R.id.fare_ll); Get id of your custom view like this ...

        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // Set property for Custom view like this.

fare_ll.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });

That's it.... You are good to go. 就是这样。...你很好。

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

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