-1

I'm trying to put a spinner on a layout for android app. Unlike other components, the spinner does not come with an option to give a hint. How can I do it?

This is my spinner:

<Spinner
    android:id="@+id/spinner_gender"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/gender"
    android:background="@android:color/white" />

When it's not selected I want to show a text like "Gender". When we select it i want that we can't select the option gender and that we only select Male or Female.

The options inside spinner are in an xml called where I keep the arrays.

Thanks.

2 Answers2

0

Unfortunately Spinner don't have this feature built-in. Please check this post

aiqency
  • 1,015
  • 1
  • 8
  • 22
0

This feature can be easily implemented through the library with so much customization:

https://github.com/Mobile-Innowise-Group/HintedSpinner

Usage of the library and with a lot of customized params:

<com.innowisegroup.hintedspinner.HintedSpinner
android:id="@+id/hintedSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
app:hintTextSize="24sp"
app:hintTextColor="@color/red"
app:hint="Custom hint"
app:withDivider="true"
app:dividerColor="@color/dark_green"
app:arrowDrawable="@drawable/example_arrow_4"
app:arrowTint="@color/colorAccent"
app:popupBackground="@color/light_blue"
app:items="@array/text" />

enter image description here