Android Question Changing selector icon in Spinner

Javier Campo Martinez

Member
Licensed User
Hi guys !!!!
I'm trying to change the Spinner's selector icon in my project, modifying the Manifest.

I'm doing this:
B4X:
<resources>
    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
        <item name="android:colorPrimary">@color/actionbar</item>
        <item name="android:colorPrimaryDark">@color/statusbar</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:navigationBarColor">@color/navigationBar</item>
        <item name="android:buttonStyle">@style/miBoton</item>
        <item name="android:textViewStyle">@style/miTexto</item>
        <item name="android:spinnerStyle">@style/miComboBox</item>
    </style>
    ...
    <style name="miComboBox" parent="@android:style/Theme">
        <item name="android:clickable">true</item>
        <item name="android:textColor">#959494</item>
        <item name="android:textStyle">normal</item>
        <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
        <item name="android:dropDownSelector">@android:color/black</item>
        <item name="android:background">@drawable/gradient_spinner</item>
        <item name="android:gravity">left</item>
        <item name="android:layout_height">wrap_content</item>
    </style>
    ...
</resources>

and I obtain the following :

20180523183651.jpeg



I need the spinner's selector icon appears as it's shown below:
gradient_spinner.png


What else do i need to specify in the manifesto?

Thanks in advance !!!!
 

Javier Campo Martinez

Member
Licensed User
Hi guys/mates/llaves
This is how i resolved my issue.

Android Manifesto
B4X:
...
<resources>
    ...
    <style name="miComboBox" parent="android:Widget.Spinner">
        <item name="android:clickable">true</item>
        <item name="android:textColor">@color/textColorPrimary</item>
        <item name="android:textStyle">normal</item>
        <item name="android:background">@drawable/background_spinner</item>
    </style>
    ...
</resources>
...

@drawable/background_spinner maps the file "background_spinner.xml" which must be copied to the folder "Objects\res\drawable"
Here is the contents of "background_spinner.xml"
B4X:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <gradient android:angle="90" android:endColor="@android:color/transparent" android:startColor="@android:color/transparent" android:type="linear" />
                    <stroke android:color="#c0c0c0" />
                    <corners android:radius="0dp" />
                    <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
                </shape>
            </item>
            <item android:right="2dp">
                <bitmap android:gravity="center_vertical|right" android:src="@drawable/gradient_spinner" />
            </item>
        </layer-list>
    </item>
</selector>


And that's the result:

resultant_spinners.jpg

Additionally, I reduced the image size to 32x32 pixels.

Finally, don't forget to mark the folder "drawable" as Read-Only once you add the resources (xml files and images) .... if you don't do it, the Big Bad Wolf will come to eat that files, when generating the application.

Hope it helps someone.

Best regards,
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Hi guys/mates/llaves
This is how i resolved my issue.

Android Manifesto
B4X:
...
<resources>
    ...
    <style name="miComboBox" parent="android:Widget.Spinner">
        <item name="android:clickable">true</item>
        <item name="android:textColor">@color/textColorPrimary</item>
        <item name="android:textStyle">normal</item>
        <item name="android:background">@drawable/background_spinner</item>
    </style>
    ...
</resources>
...

@drawable/background_spinner maps the file "background_spinner.xml" which must be copied to the folder "Objects\res\drawable"
Here is the contents of "background_spinner.xml"
B4X:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item>
                <shape>
                    <gradient android:angle="90" android:endColor="@android:color/transparent" android:startColor="@android:color/transparent" android:type="linear" />
                    <stroke android:color="#c0c0c0" />
                    <corners android:radius="0dp" />
                    <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
                </shape>
            </item>
            <item android:right="2dp">
                <bitmap android:gravity="center_vertical|right" android:src="@drawable/gradient_spinner" />
            </item>
        </layer-list>
    </item>
</selector>


And that's the result:

View attachment 68253

Additionally, I reduced the image size to 32x32 pixels.

Finally, don't forget to mark the folder "drawable" as Read-Only once you add the resources (xml files and images) .... if you don't do it, the Big Bad Wolf will come to eat that files, when generating the application.

Hope it helps someone.

Best regards,
I think it was not necessary to do all that, because the Spinners come like this by default
 
Upvote 0
Top