13

I want to show spinner with static small label above it how it can be possible seen one of the popular app want to show same like it.

Here is my image, red marked one is the spinner with gray colored text above it which does not changes

I don't want to show android:prompt which shows default text inside spinner want to show exact above the spinner in same control

enter image description here

Aditi K
  • 1,534
  • 5
  • 22
  • 43

3 Answers3

7

for this you will have to create custom spinner:

layout of spinner according to your need name it as custom_spinner:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tVStaticSmallLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="static text"
        android:textColor="#777777"
        android:textSize="22px" />

    <TextView
        android:id="@+id/tVMainText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tVStaticSmallLabel"
        android:layout_marginTop="5dip"
        android:text="your changing text" />
</RelativeLayout> 

in activity give this layout to the spinner:

Spinner mySpinner = (Spinner) findViewById(R.id.yourSpinner);
        mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner,
                spinnerValues));
Cliff Burton
  • 3,414
  • 20
  • 33
  • 47
Hamad
  • 5,096
  • 13
  • 37
  • 65
  • 2
    You should use `sp` instead of pixels for `textSize`. – Sumit Jul 10 '16 at 10:33
  • 2
    You talk about creating a custom spinner named `custom_spinner` but the layout provided doesn't even contain a spinner named `custom_spinner` that example is not helping. – Christian Beer Dec 11 '20 at 20:44
  • you are taking it wrong, custom_spinner is the new layout that you will inflate to your adapter it's not the spinner that you have added in your layout file. adapter inflate the layout to your spinner according to your given designed layout. @ChristianBeer – Hamad Mar 14 '22 at 07:11
1

That title is nothing but a TextView.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

I believe, it is a VerticalLayout with 2 items inside: one TextView and the other Spinner

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127