-1

I am trying to change the text color of spinner because my linear layout is white and the text colour is not visible on it . I have added the code for that but it's not working.

      <Spinner
        android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_marginTop="15dp"
        android:background="#f3f3f3"
        android:entries="@array/secret_arrays"
        android:focusableInTouchMode="true"
        android:paddingLeft="5dp"
        android:prompt="@string/secret_prompt"
        android:spinnerMode="dialog"
        android:textColor="#000000" />
Loren
  • 320
  • 1
  • 10
  • 25
  • Duplicate of http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color and http://stackoverflow.com/questions/18312043/how-to-change-spinner-text-color – Rohit5k2 Aug 19 '15 at 10:36
  • Please try a simple search before posting a question. – Rohit5k2 Aug 19 '15 at 10:37
  • @Rohit5k2 If you can see their solution they are doing it programmatically and i want to change using xml file only... I have seen them ..was not satisfied so posted my question..got it..!!!!! – Loren Aug 19 '15 at 10:47
  • They are using a custom texview and you need to assign that to your spinner anyway. So its not exactly programmatically – Rohit5k2 Aug 19 '15 at 10:51
  • But I want to do it via xml way .Can you suggest some way – Loren Aug 19 '15 at 10:58
  • Your text displays on a textview that is set as a view inside spinner. I don't think its possible the way you are doing it. – Rohit5k2 Aug 19 '15 at 10:59
  • I got desired result when i Defined in my manifest some theme NoTitleBar.FullSCreen but it creates some other problem so i HAVE TO REMOVE IT. – Loren Aug 19 '15 at 11:03
  • Why don't you try this way then. Its simple and clean. – Rohit5k2 Aug 19 '15 at 11:05
  • they are accessing spinner R.id spinner2 but they have defined textview – Loren Aug 19 '15 at 11:07
  • They are just using a custom textview rather than default one. See first link. – Rohit5k2 Aug 19 '15 at 11:08
  • ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinner_item,list); In this line from where spinner_item and list come from? – Loren Aug 19 '15 at 11:12
  • yes. Create a layout xml with a textview and use that in this line. – Rohit5k2 Aug 19 '15 at 11:19

2 Answers2

0

To use a custom style for spinner dropdown items:

Add in res/values/styles.xml:

 <style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item>
   </style>
 <style name="mySpinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
<item name="android:textColor">@color/my_spinner_text_color</item>
     </style>

and define your custom color in res/values/colors.xml:

 <color name="my_spinner_text_color">#808080</color>
sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • i tried thhis code.But still my text colour is white only. In androidmanifest do i need to manually define some theme for this code to work – Loren Aug 19 '15 at 10:57
0

Try this:

styles.xml

<style name="AppTheme" parent="android:Theme.Light">
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItemStyle</item>
</style>

<style name="SpinnerDropDownItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
    <item name="android:textColor">@color/spinner_text_color</item>
</style>

colors.xml

<color name="spinner_text_color">#000000</color>

AppManifest.xml

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@style/AppTheme"> //Add this if it does not exist
Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57