How to add a spinner next to a menu in the toolbar

前端 未结 2 926
清歌不尽
清歌不尽 2021-02-05 23:34

I want my spinner to be next to my menu in the toolbar (to the left of the menu), but currently the spinner appear below the menu. Do i have to add it somehow inside the o

2条回答
  •  一个人的身影
    2021-02-05 23:44

    Add menu Item

    
        
    
    

    Java

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.android_action_bar_spinner_menu, menu);
    
            MenuItem item = menu.findItem(R.id.spinner);
            Spinner spinner = (Spinner) item.getActionView();
    
            ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
                    R.array.spinner_list_item_array, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
            spinner.setAdapter(adapter);
            return true;
        }
    

    or

    
    
    
        
    
    
    

提交回复
热议问题