Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add Custom Layout for your <code>Adapter</code>. in this i have created one layout inside that i have add one <code>TextView</code>. with <code>text color</code> and <code>background color</code>.</p> <p>and set atapter like:</p> <pre><code>ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;( getBaseContext(), R.layout.my_spinner_style, R.id.textView1, COUNTRIES); </code></pre> <p>here </p> <p><code>R.layout.my_spinner_style</code> is my custom layout.</p> <p><code>R.id.textView1</code> is textview id from <code>my_spinner_style.xml</code>.</p> <p><strong>you can also applay your awn style inside TextView.</strong> check <a href="http://developer.android.com/guide/topics/ui/themes.html" rel="nofollow noreferrer">this</a> and <a href="http://developer.android.com/guide/topics/resources/style-resource.html" rel="nofollow noreferrer">this</a> aretical.</p> <p>check this code:</p> <p><img src="https://i.stack.imgur.com/piOCS.png" alt="enter image description here"></p> <p>inside <code>onCreate</code>:</p> <pre><code>/** Create an array adapter to populate dropdownlist */ ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;( getBaseContext(), R.layout.my_spinner_style, R.id.textView1, COUNTRIES); /** Enabling dropdown list navigation for the action bar */ getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); /** Defining Navigation listener */ ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { Toast.makeText(getBaseContext(), "You selected : " + COUNTRIES[itemPosition], Toast.LENGTH_SHORT).show(); return false; } }; /** * Setting dropdown items and item navigation listener for the actionbar */ getActionBar().setListNavigationCallbacks(adapter, navigationListener); </code></pre> <p>my_spinner_style.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFF00" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;/LinearLayout&gt; </code></pre>
 

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