0

I am using following style to show spinner which is having custom style

         <TableRow
                android:id="@+id/tblRwSpn11"
                style="@style/TableRowStyle" >

                <Spinner
                    android:id="@+id/btnDashCust1"
                    style="@style/ButtonStyleSpinner1"
                    android:layout_marginTop="5dp"
                    android:layout_span="2"
                    android:textSize="10sp" />
            </TableRow>

 <style name="ButtonStyleSpinner1" parent="@android:style/Widget.Spinner">
        <item name="android:textColor">@color/black</item>
        <item name="android:layout_height">35dp</item>
        <item name="android:layout_marginLeft">10dp</item>
        <item name="android:layout_marginRight">10dp</item>
        <item name="android:paddingLeft">15dp</item>
        <item name="android:textSize">@dimen/twelveTextSize</item>        
    </style>
in my SDK style.xml


 <style name="Widget.Spinner">
        <item name="android:background">@android:drawable/btn_dropdown</item>
        <item name="android:clickable">true</item>
        <item name="android:spinnerMode">dialog</item>

        <item name="android:dropDownSelector">@android:drawable/list_selector_background</item>
        <item name="android:popupBackground">@android:drawable/spinner_dropdown_background</item>
        <item name="android:dropDownVerticalOffset">-10dip</item>
        <item name="android:dropDownHorizontalOffset">0dip</item>
        <item name="android:dropDownWidth">wrap_content</item>
        <item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item>
        <item name="android:gravity">center</item>
    </style>

and @android:drawable/btn_dropdown as follows

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/btn_dropdown_normal" />
    <item
        android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/btn_dropdown_disabled" />
    <item
        android:state_pressed="true"
        android:drawable="@drawable/btn_dropdown_pressed" />
    <item
        android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/btn_dropdown_selected" />
    <item
        android:state_enabled="true"
        android:drawable="@drawable/btn_dropdown_normal" />
    <item
        android:state_focused="true"
        android:drawable="@drawable/btn_dropdown_disabled_focused" />
    <item
        android:drawable="@drawable/btn_dropdown_disabled" />
</selector>

output :

enter image description here

My Theme

  <style name="MyTheme" parent="android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/thin_ab_style</item>
</style>

<style name="MyActionBar" parent="android:style/Theme.Holo.Light">
    <item name="android:background">@color/blue</item>
    <item name="android:actionBarSize">2dp</item>
</style>

<style name="thin_ab_style" parent="android:Widget.Holo.ActionBar">
    <item name="android:height">30dp</item>
    <item name="android:background">@color/blue</item>
    <item name="android:textSize">12sp</item>
    <item name="android:textColor">@color/white</item>
</style>

it shows orange color for my spinner even if i have not set so from where it is getting set? Please check above styles I applied to spinner the press effect should show either blue or gray according to theme

Aditi K
  • 1,534
  • 5
  • 22
  • 43
  • check this http://stackoverflow.com/questions/3014152/android-changing-colors-with-themes hope you find some – Digvesh Patel Sep 09 '14 at 05:37
  • @DigveshPatel thank for help but tht orange color is due parent="@android:style/Widget.Spinner" which shows on press orange color so how to change color of pressed spinner inside SDK style.xml – Aditi K Sep 09 '14 at 05:40
  • Try to make your custom adapter for spinner item. – Haresh Chhelana Sep 09 '14 at 05:50
  • @DigveshPatel if i remove parent property is shows me spinner like -select customer- without press effect – Aditi K Sep 09 '14 at 05:54
  • hmmm it means "select custome" is one of your spinner data. so its work like this . no issue in your code . just try to set hint not data to spinner – Digvesh Patel Sep 09 '14 at 05:56
  • @DigveshPatel see the link http://stackoverflow.com/questions/8619576/android-drawing-a-button-as-a-spinner – Aditi K Sep 09 '14 at 05:58

1 Answers1

0

Just write a basic Adapter extends ArrayAdapter<Type> like doing as List View.

Override getView method for that view that you want to change.

Override getDropDown view that opened when spinner pressed.

Lastly dont forget to call Spinner.setAdapter(mAdapter)

And you can use your custom layouts to change colors or anything you want.

Good luck there.

Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30
  • thank you for help i am already using custom spinner with custom style plz read code posted – Aditi K Sep 09 '14 at 05:55
  • What i am saying you dont need to custom style. You can do it by custom layouts which has selector at backgrounds. Also dont forget to add clickable=true at the root layout of your cell. – Emre Aktürk Sep 09 '14 at 06:13