简体   繁体   中英

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. So how can I get this to work.

The emulator I am using has android version 2.3.1. For the rest everything from the actionbarsherlock works like expected.

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 . For example, from this sample project , using 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
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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