0

I don't know whether this question has been asked or not but I cannot find the answer so here I ask it.

In my android app, I want to create a spinner. But the spinner in my layout is terribly ugly.

This image is my layout. Note the yellow part marks the spinner layout in my layout.My layout

And this one is the layout of an online spinner exampleOther layout

I want my spinner style look like in the second image. I tried to copy all the code in xml file. but there is no changes in the style of the spinner.

Anyone know how to have spinner style look the same as in the second image?

UPDATE: when I click on the spinner in the second layout, it shows me a list like this(note the points on the right side of the list)

enter image description here

while my spinner can only show a normal list (have no points on the right side) I want my spinner can shows the same as that.

Ryan_Chau
  • 233
  • 2
  • 19
  • can you show the activity_main.xml – Anas Reza Aug 15 '14 at 07:50
  • 1
    Ironically, the first image shows the `Spinner` on newer Android, while the second one is pre-HoneyComb. You could try to force using `style="@android:style/Widget.Spinner"` inside your layout XML, though. – Andrew T. Aug 15 '14 at 07:55
  • What is the result on the phone? – AlexBalo Aug 15 '14 at 08:28
  • @AlexBalo The result is the same as in the layout. – Ryan_Chau Aug 15 '14 at 09:09
  • Why not giving your spinner a custom style? Something like this http://stephenpengilley.blogspot.de/2013/01/android-custom-spinner-tutorial.html – AlexBalo Aug 15 '14 at 09:11
  • @AndrewT. I tried your suggest and even though the it works for me. Now the spinner layout is better and it is almost the same as in the second. But when I click on the spinner in the second one, it shows up a list that looks like in this image http://www.mkyong.com/wp-content/uploads/2011/11/android-spinner-demo2.png So can you suggest me ways to show up things like the link above? Thanks – Ryan_Chau Aug 15 '14 at 09:13
  • @AlexBalo As Andrew said, it is just different version of spinner. I think there is a way to make newer one appeared as the older one. So no need to make a custom spinner – Ryan_Chau Aug 15 '14 at 09:17
  • Are you sure about that? – AlexBalo Aug 15 '14 at 09:20
  • I see, basically you want to have the old `Spinner` behaviour. I found a solution, but the drawback is, you won't be using Holo at all and it affects all elements. You need to delete `styles.xml` in `/res/values-v11` and `/res/values-v14`. (You might backup it first in case you want to change your mind). Perhaps there's a better way to only stylize the `Spinner`, but I don't know. – Andrew T. Aug 15 '14 at 09:22
  • @AnasReza: As I mentioned in the questions, I have tried to make both xml files the same. but there is no changes in the layout. – Ryan_Chau Aug 15 '14 at 09:24
  • @AndrewT. Do you know what is the advantage when they make the new behaviour for Spinner? – Ryan_Chau Aug 15 '14 at 09:25

2 Answers2

1

if you just want to have the spinner to be "holofied" you can do this:

<Spinner
  android:id="@+id/spinnermap"
  style="@style/MySpinnerStyle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_centerVertical="true" />

values/styles.xml:

<style name="MySpinnerStyle" parent="android:Widget.Spinner"> </style>

Mykhailo
  • 331
  • 3
  • 18
  • Thanks for you answer, but its not what i want though:D – Ryan_Chau Aug 15 '14 at 08:59
  • Now the spinner layout is better and it is almost the same as in the second. But when I click on the spinner in the second one, it shows up a list that looks like in this image http://www.mkyong.com/wp-content/uploads/2011/11/android-spinner-demo2.png So can you suggest me ways to show up things like the link above? – Ryan_Chau Aug 15 '14 at 09:14
  • Unfortunately i can not open a picture. But if you need MultiSelectSpinner : [link](http://stackoverflow.com/questions/2682582/spinner-with-checkbox-items-is-it-possible) , [link2](http://stackoverflow.com/questions/5015686/android-spinner-with-multiple-choice) Also you can create your own adapter and layout with checkboxes. And set list in a dialog : `android:spinnerMode="dialog" ` – Mykhailo Aug 15 '14 at 11:38
0

set below attr for your spinner

android:spinnerMode="dropdown"  

but it work for newer android version for older you can use support library or using IcsSpinner

MHP
  • 2,613
  • 1
  • 16
  • 26
  • the suggested list is changed to drop down list but the list does not has the points (as I mentioned in the question) that I want – Ryan_Chau Aug 15 '14 at 10:04