Add Spinner To Action Menu Bar

I am looking for an example of how to add a Spinner element with an array of elements to the Android menu options.

I look at many examples, but there is no simple example that I can follow. I want to add an item to the Action Bar at the top of the screen.

+6
source share
3 answers

Spinner in Right on Action Bar Sherlock with IcsLinearLayout

ABS Custom Spinner in right

private String[] mLocations; ActionBar actionBar = getSupportActionBar(); final Context themedContext = actionBar.getThemedContext(); ArrayAdapter<String> adapter = new ArrayAdapter<String>(themedContext, R.layout.sherlock_spinner_item, mLocations); adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); // create ICS spinner spinner = new IcsSpinner(this, null, R.attr.actionDropDownStyle); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(IcsAdapterView<?> parent, View view, int position, long id) { } @Override public void onNothingSelected(IcsAdapterView<?> parent) { } }); // configure custom view IcsLinearLayout listNavLayout = (IcsLinearLayout) getLayoutInflater() .inflate(R.layout.abs__action_bar_tab_bar_view, null); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; listNavLayout.addView(spinner, params); listNavLayout.setGravity(Gravity.RIGHT); //align the spinner to the right // configure action bar actionBar.setCustomView(listNavLayout, new ActionBar.LayoutParams( Gravity.RIGHT)); 
+1
source

It is very simple, you get the option at the beginning when you create a new project.

Look at my attached image and you will get more ideas.

Like my answer if that helps you.

thanks

enter image description here

+4
source

You can get the full answer to your decision here.

0
source

Source: https://habr.com/ru/post/955375/


All Articles