- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想避免在单击操作栏中的 < 按钮时破坏父 Activity 。
当我们按下那个按钮时,从 AppCompatActivity 调用了哪个方法?
我有办法覆盖它吗?有没有办法覆盖所有 Activity ?
最佳答案
i'd like to avoid parent activity being destroyed whenever i clicked < button in action bar.
一旦您按下该按钮,您的父 Activity 将暂停,而不是被销毁。
is there a way for me to override it? and is there a way to override for all activities?
只需调用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
您需要将它调用到要覆盖按钮的 Activity 中。没有其他选择可以称之为“一劳永逸”。
which method is being called from AppCompatActivity when we press that button?
默认情况下,其中没有方法。如果您使用 Toolbar
,请调用 setNavigationOnClickListener()
以在按下该按钮时执行某些操作。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something here, such as start an Intent to the parent activity.
}
});
如果您使用 ActionBar
,该按钮将在 Menu
上可用:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// do something here, such as start an Intent to the parent activity.
}
return super.onOptionsItemSelected(item);
}
关于android - 覆盖操作栏中的向上按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679133/
我在让我的操作栏显示图标时遇到问题。它显示了我在溢出菜单中设置的文本/标题(三个点),但没有任何操作。这是我的代码,我错过了什么? MainActivity.java public class Mai
我正在尝试在 android 中制作一个动态操作栏,现在我正在尝试像这样在操作栏中进行搜索。 http://developer.android.com/images/ui/actionbar-sear
我正在编写 uiautomator 测试,但我很难弄清楚如何单击我的操作栏图标。 如果我的操作是“始终”显示,则很容易找到并点击。 如果我的操作是显示“从不”,我必须单击菜单,然后从菜单中单击。先点击
我有一个正在寻找特定 URI 的重写规则。当它匹配特定的 URL 时,它会使用正确的文件路径重写它,以便可以找到所需的内容。然后它将协议(protocol)更改为 HTTPS 并允许请求通过。 我有两
我正在为 android 中的 ActionBar 而苦苦挣扎。 这是我的问题:我的操作项没有显示在操作栏中,而是堆叠在操作溢出中,无论我做什么.. 我花了一天的时间寻找解决方案,但我似乎找不到缺少的
我的网络应用程序在 Tomcat 下运行,它非常密集地使用 AJAX 请求,在开发过程中我也必须密集地重新部署网络应用程序。重新部署后,我通常会简单地刷新页面,知道用户 session 已删除,但我总
我是一名优秀的程序员,十分优秀!