2013-08-21 41 views
1

我想在操作欄中添加一個標準的向上按鈕圖標(<這樣)。向上按鈕自定義中的欄

我的風格添加了這個:

<style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
     <item name="android:homeAsUpIndicator">@drawable/navigation_previous_item</item> 
</style> 

我啓用了Home鍵在onCreate

getActionBar().setHomeButtonEnabled(true); 

而增加動作事件:

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch(item.getItemId()){ 
      case android.R.id.home: 
       onBackPressed(); 
       break; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
     return true; 
    } 

問題是我看不到(<)圖標。應用程序圖標被填充到右側,就像我的繪圖有一個地方,但它不會顯示圖標。 。 。

+2

您還需要調用:'getActionBar()setDisplayHomeAsUpEnabled(真)'。在啓用該選項後,看看是否使用'getActionBar()。setHomeAsUpIndicator(getResources()。getDrawable(R.drawable.navigation_previous_item))'help。 – Vikram

+0

非常感謝,我一直在呼喚這種方法:D – Jilberta

+0

不客氣。您可以接受@ andreich的答案,因爲它提出了相同的方法。 – Vikram

回答

1

嘗試getActionBar().setDisplayHomeAsUpEnabled(true);,它應該工作