【问题标题】:Actionbarsherlock back button doesn't go backActionbarsherlock 后退按钮不返回
【发布时间】:2012-05-04 13:09:30
【问题描述】:

当我按下主页按钮时,它并没有像我想象的那样返回。

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

}

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

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

但这不起作用我确实进入了这个方法,但 id 不是同一个 id 作为 R.id.abs__home。那么我怎样才能让它工作呢。

我使用的模拟器是 android 版本 2.3.1。其余的一切从 actionbarsherlock 按预期工作。

蓝色块是我点击的按钮,点击后我想返回。

【问题讨论】:

    标签: android actionbarsherlock


    【解决方案1】:

    使用android.R.id.home 检测家庭功能,而不是R.id.abs__home。例如,来自this sample project,使用 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
      }
    

    【讨论】:

    • 好的,我现在知道了,现在我只需要将它发送到上一个操作。所以谢谢。
    • 重点是使用android.R.id.home。我仅使用 R.id.home 进行了尝试,并依赖生成的 R 而不是 Androids R。感谢您的澄清:)
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2014-06-04
    • 2013-12-02
    相关资源
    最近更新 更多