[英]Actionbarsherlock back button doesn't go back
When I press the home button it doesn't go back like I think it would do. 当我按下主页按钮时,它不会像我想的那样回去。
public class TotalOverview extends SherlockActivity {
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_PROGRESS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setContentView(R.layout.main);
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
I also tried catching it with this method 我也试过用这种方法来捕捉它
public boolean onOptionsItemSelected(MenuItem item)
{
boolean toReturn = false;
int id = item.getItemId();
if( id == R.id.abs__home)
{
toReturn = true;
}
return toReturn;
}
but that didn't work I did get into this method but the id is not the same id as the R.id.abs__home. 但这不起作用我确实进入了这个方法,但id与R.id.abs__home的id不同。 So how can I get this to work.
那么我怎样才能让它发挥作用。
The emulator I am using has android version 2.3.1. 我使用的模拟器有android版本2.3.1。 For the rest everything from the actionbarsherlock works like expected.
对于其余部分,来自actionbarsherlock的所有内容都像预期的那样工作。
The blue block is the button I click, and with clicking that I want to navigate back. 蓝色块是我点击的按钮,点击后我想要导航回来。
Use android.R.id.home
to detect the home affordance, not R.id.abs__home
. 使用
android.R.id.home
来检测家庭R.id.abs__home
性,而不是R.id.abs__home
。 For example, from this sample project , using ABS 4.0.2: 例如,从此示例项目中 ,使用ABS 4.0.2:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
pager.setCurrentItem(0, false);
return(true);
// more code here for other cases
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.