B4J Question combobox and textcolor

kpmais

Member
Licensed User
Longtime User
Hi everyone,

I want to change the text color in a combobox. Specifically, the color of the text displayed in the upper text area.

The method `mycombobox.As(b4xview).textcolor = xxxx` isn't working.

Setting a style like `-fx-text-fill: xxxx` also doesn't work.

Any help would be greatly appreciated.
 

behnam_tr

Active Member
Licensed User
Longtime User
test this

B4X:
.combo-box .list-cell {
    -fx-text-fill: white;
}

.combo-box {
    -fx-prompt-text-fill: white;
}

.combo-box .arrow-button .arrow {
    -fx-background-color: white;
}

.combo-box .label {
    -fx-text-fill: yellow;
}

B4X:
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "style.css"))
 
Upvote 0

kpmais

Member
Licensed User
Longtime User
Thank you for your reply. I've already found similar solutions online.

But I don't know how to implement this in b4j.

I suspect these styles are stored in the style.css file. But what does such a string look like? And how do I reference the style when I need it?
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Maybe a option to use the Library CSSUtils
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User

@behnam_tr gave you the answer in message #2.
Here are the steps you can take to make it work:
1. copy the stylesheets line in the Main module (see highlighted line):
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "styles.css"))
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub
2. create a styles.css file (with an editor like Notepad++ for instance) and copy the styles information from message #2 into it.
styles.css:
.combo-box .list-cell {
    -fx-text-fill: red;
}

.combo-box {
    -fx-prompt-text-fill: red;
}

.combo-box .arrow-button .arrow {
    -fx-background-color: red;
}

.combo-box .label {
    -fx-text-fill: white;
}
In the highlighted lines i have changed the colors: red in stead of white and white in stead of yellow.
Save the styles.css file and add it in the Files Manager of the IDE.
3. Add the ComboBox in the designer and set the color (=background color) to lightblue for instance. Generate the member.
4. In the B4XMainPage module (B4XPage_Created subroutine) you can write some code to fill the ComboBox:
B4X:
    Dim lst As List = Array As String("item 1","item 2","item 3")
    ComboBox1.Items.AddAll(lst)
    ComboBox1.SelectedIndex = 0
5. run the application.

Note: when you check the ComboBox property Editable in the designer then the textfield text will not take the red color.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…