2014-02-22 39 views
0

出於某種原因,我無法訪問我的應用程序的主頁圖標,因爲它沒有通過id定義,而是在清單中定義。我希望能夠爲此操作欄圖標設置onclick監聽器。 在這種方法中,我設定的圖標,但我不知道如何設置這個一個onclick監聽器,因爲它不是由一個IDAndroid actionBar Home啓用,設置點擊監聽器

public void actionBarSetUp() { 
    // get action bar 
    ActionBar actionBar = getActionBar(); 

    // Enabling Up/Back navigation 
    actionBar.setDisplayHomeAsUpEnabled(true); 


    // set the icon 
    actionBar.setIcon(R.drawable.app_logo_high_res); 

} 
+0

'android.R.id.home'是'View'的ID。 – adneal

+0

android.R.id.home在我的資源中不存在 – user2219097

+0

'android.R.id.home'在系統資源中定義。你需要導入'android.R'類... –

回答

0

你的活動應該定義擴展ActionBarActivity因爲這樣你可能有此覆蓋可用: -

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     // Respond to the action bar's Up/Home button 
     case android.R.id.home: 
      finish(); // Or what ever action you want here. 
      return true; 
    } 
    return super.onOptionsItemSelected(item); 
}