1

I have the following layout XML:

<android.support.v7.widget.AppCompatSpinner
            android:id="@+id/content_spinner"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/border"
            android:entries="@array/books"
            android:spinnerMode="dropdown"
            android:theme="@style/large_spinner"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

And @style/large_spinner looks like this:

 <style name="large_spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
        <item name="android:paddingStart">0dp</item>
        <item name="android:paddingEnd">0dp</item>
        <item name="android:textColor">@color/nearlyBlack</item>
        <item name="android:textSize">30sp</item>
        <item name="android:drawableRight">@drawable/ic_menu_camera</item>
    </style>

Which gives me the camera icon to the right of the spinner, which is want. However when I drop down the spinner the icon is on every single item, which I dont want. I just want the icon to the right on the spinner, not in every single item.

How can i achieve this?

Óscar
  • 809
  • 1
  • 8
  • 33
Chud37
  • 4,907
  • 13
  • 64
  • 116

1 Answers1

1

Try this

<android.support.v7.widget.AppCompatSpinner
    android:id="@+id/content_spinner"
    style="@style/Widget.AppCompat.Spinner.Underlined"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/test"
    android:entries="@array/books"
    android:spinnerMode="dropdown"
    android:theme="@style/large_spinner"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

android:background="@drawable/test"

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <solid android:color="@android:color/white" />
                    <corners android:radius="4dp" />
                    <padding android:left="8dp" />
                </shape>
            </item>

            <item  android:gravity="left|bottom" android:drawable="@drawable/ic_menu_camera" />

        </layer-list>
    </item>
</selector>

style name="large_spinner"

<style name="large_spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
    <item name="android:paddingStart">0dp</item>
    <item name="android:paddingEnd">0dp</item>
    <item name="android:textColor">@color/nearlyBlack</item>
    <item name="android:textSize">30sp</item>
</style>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • This doesnt work, produces a bunch of errors that are not helpful, I cant work out what they mean – Chud37 Aug 01 '18 at 08:13