简体   繁体   English

Android ActionBar自定义行为

[英]Android ActionBar custom behaviour

I created fully custom action bar, removed all native control from there and added button in left side. 我创建了完全自定义的操作栏,从那里删除了所有本机控件并在左侧添加了按钮。

This is done in order to get full control over action bar layout. 这样做是为了完全控制操作栏布局。 Now when user clicks on this button i want to grant the same functionality as Native Up button. 现在,当用户点击此按钮时,我想授予与Native Up按钮相同的功能。

In other words i from my button click event i need the same functionality as default code here. 换句话说,我从我的按钮点击事件我需要与默认代码相同的功能。

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return(super.onOptionsItemSelected(item));
    }

How this can be achieved? 如何实现这一目标?

Thanks. 谢谢。

Switch android.R.id.home with the id of the custom button, R.id.menu_button_name. 切换android.R.id.home,其ID为自定义按钮R.id.menu_button_name。

ActionBar is now being replaced with Toolbar which gives you more control and customization options than ActionBar. ActionBar现在被替换为工具栏 ,它提供了比ActionBar更多的控制和自定义选项。 Here are some examples of what you can do with the Toolbar these days. 以下是您最近可以使用工具栏执行的操作的一些示例

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

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