2016-12-03 76 views
0

我從我的片段片段的主頁圖標

public synchronized void setToolbarTitle(String title) { 
     if(toolbarTitle !=null) { 
      toolbarTitle.setText(title); 
     } 

     if(title.contains("Dashboard")) { 
      drawer.addDrawerListener(toggle); 
      getSupportActionBar().setDisplayHomeAsUpEnabled(false); 
      getSupportActionBar().setDisplayShowHomeEnabled(false); 
      toggle.setDrawerIndicatorEnabled(true); 
     } else if(!title.contains("Dashboard")) { 
      drawer.removeDrawerListener(toggle); 
      toggle.setDrawerIndicatorEnabled(false); 
      getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
      getSupportActionBar().setDisplayShowHomeEnabled(true); 
     } 
    } 

內調用此MainActivity功能現在,如果我通過任何標題,除了「儀表板」,它顯示爲預期家庭指標。但是,單擊該指示器什麼也不做。我希望它能效仿onBackPressed()

onOptionsItemSelected如下:在您的片段onCreateView方法

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 
    Log.i("Here","Here"); 
    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } if (id == android.R.id.home) { 
     onBackPressed(); 
     return true; 
    } if (id == R.id.homeAsUp) { 
     onBackPressed(); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

回答

0

使用本

setHasOptionsMenu(true);