2013-03-23 58 views
0
private void setListNavigation(ActionBar bar) { 
    String[] actions = new String[] { 
     "Bookmark", 
      "Subscribe", 
      "Share" 
    }; 
    ArrayAdapter <String> adapter = new ArrayAdapter <String> (getBaseContext(), android.R.layout.simple_spinner_dropdown_item, actions); 
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
    bar.setDisplayShowTitleEnabled(false); // hide application title from action bar 
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#dedfde"))); 

} 

當我嘗試添加微調到我的操作欄,它不顯示。我只是單獨得到小箭頭圖標。微調列表不顯示我的操作欄?

下面是我onCreate()方法

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_prime_mobile_home);    
    ActionBar bar = getActionBar(); 
    setListNavigation(bar);  
} 

回答

3

這是工作代碼在操作欄設置導航微調嘗試了這一點

arrayItemsForDropdown = getResources().getStringArray(R.array.order); 
Context context = getSupportActionBar().getThemedContext(); 
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context,R.array.order, R.layout.sherlock_spinner_item); 
list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); 
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
getSupportActionBar().setListNavigationCallbacks(list, this); 
1

你忘了添加

bar.setListNavigationCallbacks(適配器,這一點);

setListNavigation

,讓你的類實現ActionBar.OnNavigationListener