PaolaJ.
PaolaJ.

Reputation: 11532

How to set style in spinner

How to set style on spinner ? I have style with font size and family for custom edit text class and I need same for spinner. I tried to add style tag in spinner xml but it is ignored, I tried in adapter but it doesn't work.

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, tempList) {
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);
        Typeface externalFont = Typeface.createFromAsset(getAssets(), "fonts/CANDARA.TTF");
        ((TextView) v).setTypeface(externalFont);
        return v;
    }
}

Upvotes: 0

Views: 1109

Answers (3)

Nil
Nil

Reputation: 324

you want to add customize spinner

for that see these two link it might be help you .

Link 1 normal as you want just changing text and all that,

and for hover effect on your spinner look this link . Link2

Upvotes: 1

DSS
DSS

Reputation: 7259

You are passing the default android layout for the spinner items, instead create your own layout like:

    <RelativeLayout
         android:id="@+id/rel"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content">
        <TextView
               android:id="@+id/txtSpinnerItem"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               stlye="@style/txtViewStyleHere"/>
    </RelativeLayout>

Pass this layout to the adapter, in that case, you will have to create your own adapter class to access the textView.

Upvotes: 1

Anid Monsur
Anid Monsur

Reputation: 4538

Instead of using the simple spinner layout android.R.layout.simple_spinner_item, create your own layout file containing a TextView and style it the way you'd like. Then, pass a reference to that layout when you instantiate the ArrayAdapter.

Upvotes: 1

Related Questions