Android Question How to change background color of a Spinner?

Creideiki

Active Member
Licensed User
Longtime User
Hi,

actually Spinner seem to be colored gray in gray. So the only hint that that's a spinner is little array at the right.

Now it's easy to change the background color eg with
B4X:
spinner.Color = Colors.LightGray

BUT - now the little arrow is gone.

I tried a bit with the blend modes like here, but it seems not to be possible to change the whole background this way.

What's the correct way to change only the background color of a Spinner without killing the arrow?
 

Mahares

Expert
Licensed User
Longtime User
What's the correct way to change only the background color of a Spinner without killing the arrow?
If you use B4XComboBox, it is more versatile. You can change its background to say yellow in the designer and use the below code to display the down arrow in blue.
B4X:
Dim jo As JavaObject = B4XComboBox1.cmbBox.Background
    jo.RunMethod("setColorFilter", Array(Colors.Blue, "SRC_ATOP")) 'you can use xui colors too
 
Upvote 1

Creideiki

Active Member
Licensed User
Longtime User
Sorry for the delay.

It seems there is in fact only the possibility to use B4XComboBox instead
That's not too difficult, but with a few more Spinners to replace it is a bit of work.

Here's what to do:
B4X:
# Replace the Spinner with a B4XComboBox in the designer

# E.g. we have:
Dim sp as Spinner
Dim cmb as B4XComboBox

# Replace initialisation
sp.Clear
sp.Add("Entry 1")
sp.add("Entry 2")
# with
cmb.SetItems(Array As String("Entry 1", "Entry 2"))
# If you have a List with the data either, you can use it directly with SetItems.
# If you need the old Clear/Add thing, you can
cmb.cmbBox.Clear
cmb.cmbBox.Add("Entry")

# Since it is not possible to set the TextSize in the designer, you have to
cmb.cmbBox.TextSize = 14

# To set Visible or Enabled you have to
cmb.mBase.Visible = True
cmb.mBase.Enabled = False

# SelectedIndex is the same:
cmb.SelectedIndex = sp.SelectedIndex

# Instead of
Sub sp_ItemClick (Position As Int, Value As Object)
End Sub
#you use
Sub cmb_SelectedIndexChanged (Position As Int)
End Sub

Perhaps this helps someone. :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
B4X:
# Since it is not possible to set the TextSize in the designer, you have to
cmb.cmbBox.TextSize = 14#
You can set the TextSize in the Designer in the Text Properties!

1638275734536.png
 
Upvote 0
Top