Android ActionBar (ActionBarCompat) Spinner Dropdown list ?

后端 未结 5 2092
无人共我
无人共我 2021-02-09 15:45

I am currently working ActionBar (ActionBarCompat) oriented project, I Need some Clarification about actionbar.

I am using spinner layout like this,

<         


        
5条回答
  •  太阳男子
    2021-02-09 16:42

    I feel it's time to start migrating from ABS to ABC easily by ActionBarCompat library!

    Solution for spinner (Dropdown list) using ActionBarCompat library

    private void setupSpinner(MenuItem item) {
        //  item.setVisible(getSupportActionBar().getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST);
            item.setVisible(ab.getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST);
    
            View view = item.getActionView();
            Context context = ab.getThemedContext(); //to get the declared theme
            if (view instanceof Spinner) {
                Spinner spinner = (Spinner) view;
    
                ArrayAdapter listAdapter =ArrayAdapter.createFromResource(context,
                        R.array.spinner_data,
                        R.layout.support_simple_spinner_dropdown_item);
                listAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
                spinner.setAdapter(listAdapter);
    
    
    
            }
    

    make sure you have added following in style.xml: