Actionbarsherlock后退按钮不会返回

mar*_*rio 11 android actionbarsherlock

当我按下主页按钮时,它不会像我想的那样回去.

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);

}
Run Code Online (Sandbox Code Playgroud)

我也试过用这种方法来捕捉它

public boolean onOptionsItemSelected(MenuItem item)
{
    boolean toReturn = false;
    int id = item.getItemId();  
    if( id == R.id.abs__home)
    {
        toReturn = true;
    }
    return toReturn;
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用我确实进入了这个方法,但id与R.id.abs__home的id不同.那么我怎样才能让它发挥作用.

我使用的模拟器有android版本2.3.1.对于其余部分,来自actionbarsherlock的所有内容都像预期的那样工作.

蓝色块是我点击的按钮,点击后我想要导航回来. 在此输入图像描述

Com*_*are 43

使用android.R.id.home来检测家启示,不是R.id.abs__home.例如,从此示例项目中,使用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
  }
Run Code Online (Sandbox Code Playgroud)

  • 尝试过,但它没有帮助,但感谢你的努力. (2认同)