Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to create a custom layout for the view containing the spinner. Inflate and place it on the action bar and you're good to go. </p> <p>Here you have some sample code for this(this is what you do inside your activity to initialize and place your layout on the action bar):</p> <pre><code> LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE); final View spinnerView = inflater.inflate(R.layout.layout_spinner, null); Spinner spinner = (Spinner) spinnerView.findViewById(R.id.my_spinner); ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this, R.array.spinner_items_array, R.layout.spinner_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { // Do whatever you want with your selected item. You can get it as: parent.getItemAtPosition(position); } @Override public void onNothingSelected(AdapterView&lt;?&gt; parent) {} }); getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_actionbar_logo));//set your actionbar logo getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE ); LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.RIGHT; // set your layout's gravity to 'right' getSupportActionBar().setCustomView(spinnerView, layoutParams); //place your layout on the actionbar </code></pre> <p>Your layout should look something like this (layout_spinner.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Spinner style="@style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar" android:id="@+id/my_spinner" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Your array stored in a res folder (spinner_items_array):</p> <pre><code> &lt;string-array name="spinner_items_array"&gt; &lt;item&gt;Item1&lt;/item&gt; &lt;item&gt;Item2&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>The spinner custom item (spinner_item.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cab_spinner_item" style="?android:attr/spinnerItemStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="inherit" android:textColor="@android:color/white" /&gt; &lt;!-- Set whatever color you want for the text --&gt; </code></pre> <p>And finally the drop-down list item (spinner_dropdown_item.xml): </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/spinnerDropDownItemStyle" android:layout_width="match_parent" android:layout_height="48dp" android:ellipsize="marquee" android:singleLine="true" android:textAlignment="inherit" android:textColor="@android:color/white" /&gt; </code></pre> <p>I hope this answer will help you!! Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload