[英]How to check if the back button of the ActionBarSherlock was clicked?
我正在使用庫ActionBarSherlock,並放置一個具有android:showAsAction="ifRoom|collapseActionView"
屬性的項目。 如何檢查是否已單擊ActionBarSherlock的后退按鈕? 謝謝!
你必須重寫
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
}
return true;
}
從文檔:
只要在選項菜單中選擇一個項目,他的鈎子就會被調用。 默認實現只是返回false以使正常處理發生(調用該項目的Runnable或酌情向其Handler發送消息)。 您可以將這種方法用於任何您想要對其進行處理而無需其他功能的項目。
上面的答案有效(謝謝)。 但對於我的代碼,此解決方案效果最好...
@Override
public boolean onOptionsItemSelected(
com.actionbarsherlock.view.MenuItem item) {
item.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// running changes ...
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// running changes ...
return true;
}
});
return super.onOptionsItemSelected(item);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.