0

The materialspinner is not showing any hints or labels.

This is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://shcemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:minWidth="300dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:padding="16dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <fr.ganfra.materialspinner.MaterialSpinner
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/eventnameSpinner"
            app:ms_enableFloatingLabel="true"
            app:ms_floatingLabelText="Select Event"
            app:ms_hint="Select Event"
            app:ms_alignLabels="true"/>

        <fr.ganfra.materialspinner.MaterialSpinner
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/eventpackageSpinner"
            app:ms_enableFloatingLabel="true"
            app:ms_floatingLabelText="Select Package"
            app:ms_hint="Select Package"
            app:ms_alignLabels="true"/>

</LinearLayout>

With the code

app:ms_floatingLabelText="Select Package"
            app:ms_hint="Select Package"

it is supposed to show when running the app, instead it only shows the content inside it. It is supposed to show a hint "Select Event" and "Select Package" for both spinners but it did not, and when clicking the spinner, the label would hover on top same as the EditTexts. Is there something missing? This is the layout

Zeno
  • 11
  • 3

1 Answers1

0

Are you using nuget Nivaes.Droid.Ganfra.MaterialSpinner,right?

I found that this nuget hasn't been updated for several years and is not recommended.

But you can use Xamarin.Android Spinner as an alternative.

<Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
    />

Similarly, when setting property prompt, the spinner does not display the value of prompt.

But when we set property style="@android:style/Widget.Spinner" for spinner, if we set data resource for the Spinner and click the Spinner, the prompt will display in a dialog.

    <Spinner
    style="@android:style/Widget.Spinner"
    android:tooltipText="abc"
    android:id="@+id/spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/planet_prompt"
  />

Of course, you can also add a TextView to display the prompt,just as document Xamarin.Android Spinner says.

<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="@string/planet_prompt"
    />
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
    />

Note:

You can check the following threads for more ideas:

How to make an Android Spinner with initial text "Select One"?

Spinner prompt not showing

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • @Jessia Zhang Thank you for the reply. I am actually using the nuget **MaterialSpinner-Xamarin** and using **fr.ganfra.materialspinner.MaterialSpinner** as my spinner. The reason why I am using this type of spinner is because of the design, somewhat simple but looks good in our layout. I tried changing my MaterialSpinner to Spinner and added your code and I have errors like the _prompt is not found_ and looks a bit different wherein the design is not balanced. – Zeno Nov 16 '22 at 12:21
  • In general, we recommend using official controls because they are maintained and updated by professional developers in a timely manner. Of course, you can also custom the control by yourself according to your needs. – Jessie Zhang -MSFT Nov 18 '22 at 09:35