0

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;
    }
}
takendarkk
  • 3,347
  • 8
  • 25
  • 37
PaolaJ.
  • 10,872
  • 22
  • 73
  • 111

3 Answers3

1

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.

Anid Monsur
  • 4,538
  • 1
  • 17
  • 24
1

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.

1

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

Community
  • 1
  • 1
Nil
  • 312
  • 4
  • 19