简体   繁体   English

Codenameone 如何更改选择器文本颜色

[英]Codenameone How to change Picker Text color

Picker has two components : Picker 有两个组件:

  1. The Initial/Selected value displayed in Codenameone UI . Codenameone UI 中显示初始/选定值
  2. The Native picker dialogs/sheets.机选择器对话框/工作表。

It makes sense that we can not control the theme/color/style of Native Pickers as they are influenced by an OS-specific theme selected by the user.我们无法控制Native Pickerstheme/color/style是有道理的,因为它们受用户选择的操作系统特定主题的影响。

But how do we change the color of text inside the picker in Codenameone Interface?但是我们如何在 Codenameone 界面中更改选择器内文本的颜色? What I want to do in the following screenshot is to make the texts " 3/20/20, 00:00, & 0-5 persons " white.在下面的屏幕截图中,我想要做的是将文本“3/ 3/20/20, 00:00, & 0-5 persons3/20/20, 00:00, & 0-5 persons白色。

What I tried :我试过的:

  1. Channing the "Label" font-family in CSS changed the font so I tried changing the "color" from CSS but it didn't help.在 CSS 中更改“标签”字体系列更改了字体,因此我尝试从 CSS 更改“颜色”,但没有帮助。
  2. I tried changing the foreground color like this : timePicker.style.fgColor = 0xfffff我尝试像这样更改前景色: timePicker.style.fgColor = 0xfffff
  3. In CSS I defined a style.在 CSS 中,我定义了一个样式。

     DropdownStyle{ background-color: #333333; color: #FFFFFF; }

    Then I set the style to picker然后我将样式设置为选择器

    datePicker.uiid ="DropdownStyle"

But none of the above ways worked as expected.但是上述方法都没有按预期工作。

What is the right way to do it?正确的做法是什么? I believe I am missing a very simple thing but I couldn't find it myself.我相信我错过了一件非常简单的事情,但我自己找不到。

在此处输入图片说明

在此处输入图片说明

AS @shai-almog suggested, after digging through Component Inspector , I found out that AS @shai-almog 建议,在挖掘Component Inspector 后,我发现

在此处输入图片说明

  • A PickerComponent has the ID "TextComponent" so if we replace the UIID of PickerComponent it's going to change the style of just the Holder Component that's why I was able to change the background-color only but not the text . PickerComponent的 ID 为"TextComponent"因此如果我们替换UIIDPickerComponent它将仅更改Holder Component的样式,这就是为什么我只能更改 background-color 而不能更改 text
  • Inside it, there is Picker which Represents the Text and has the id TextComponentField .在它里面,有一个Picker代表文本并且具有 id TextComponentField

So I had to Style them individually like this :所以我不得不像这样单独设计它们:

    TextComponent{
        background-color: rgba(0, 0, 0, 0.0);

    }
    TextComponentField{
        color: white;
    }

Output :输出 :

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM