Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the color of the spinner NOT the dropdown items?
    primarykey
    data
    text
    <p>I have added a Spinner with a custom listadapter which uses this layout:</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="@android:id/text1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center" android:textColor="@drawable/default_spinner_item_text" android:text="Sample Text" android:textSize="20dp" android:paddingBottom="7.5dp" android:background="@drawable/default_spinner_item" android:paddingTop="7.5dp"&gt; &lt;/TextView&gt; </code></pre> <p>Drawable default_spinner_item:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="@color/default_button_text_color" /&gt; &lt;item android:state_checked="true" android:drawable="@android:color/transparent"/&gt; &lt;item android:state_single="true" android:drawable="@android:color/transparent"/&gt; &lt;item android:state_active="true" android:drawable="@android:color/transparent"/&gt; &lt;item android:state_first="true" android:drawable="@android:color/transparent"/&gt; &lt;item android:state_focused="true" android:drawable="@android:color/transparent" /&gt; &lt;item android:state_selected="true" android:drawable="@android:color/transparent" /&gt; &lt;item android:drawable="@color/default_button_border_color" /&gt; &lt;/selector&gt; </code></pre> <p>The spinner allways gets the same color as the dropdown items...</p> <p>I have tried all the states but it seams impossible to make the spinner item background transparent and the dropdown list colored (default_button_border_color).</p> <p><strong>@Solved</strong></p> <p>This is my Adapter:</p> <pre><code>public class CustomSpinnerAdapter extends ArrayAdapter&lt;String&gt; { private int _resource; private Typeface _typeFace; public CustomSpinnerAdapter(MainActivity context, int resource, List&lt;String&gt; items) { super(context, resource, items); _resource = resource; _typeFace = context.getDefaultAppTypeFace(); } @Override public View getView(int position, View convertView, ViewGroup parent) { TextView view = (TextView)super.getView(position, convertView, parent); if(convertView == null) view.setTypeface(_typeFace); } return view; } @Override public TextView getDropDownView(int position, View convertView, ViewGroup parent) { TextView view = (TextView) super.getDropDownView(position, convertView, parent); if(convertView == null) view.setTypeface(_typeFace); } return view; } } </code></pre> <p>I now use two layouts, one for the view and one for the dropdownview. Another error in my code was that I called super.getView(position, convertView, parent); in the getDropDownView ovverride.</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.
 

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