微调器列表没有显示我的操作栏?

时间:2013-03-23 09:05:08

标签: android

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);       
}

2 个答案:

答案 0 :(得分: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 :(得分:1)

您忘了添加

  

bar.setListNavigationCallbacks(adapter,this);

setListNavigation

让你的类实现ActionBar.OnNavigationListener