设置AutoCompleteTextField的弹出列表的样式

时间:2019-04-13 16:19:50

标签: codenameone

以下代码不适用于设置AutoCompleteTextField弹出窗口的样式。解决办法是什么?

Java:

    Form hi = new Form("CSS Test", BoxLayout.y());
    AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek");
    ac.setMinimumElementsShownInPopup(5);
    hi.add(ac);
    hi.show();

CSS:

AutoCompleteList {
    font-size: 2.5mm;
    font-family: "native:MainLight";
    color: black;
    background-color: white;
}

AutoCompleteList.pressed, AutoCompleteList.selected {
    color: blue;
}

屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:1)

我刚刚找到了可能的解决方案:

Java

10.0.2.2

    Form hi = new Form("CSS Test", BoxLayout.y());
    AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek");
    ac.setMinimumElementsShownInPopup(5);
    ac.setCompletionRenderer(getCompletionRenderer());
    hi.add(ac);
    hi.show();

CSS:

private ListCellRenderer getCompletionRenderer() {
    DefaultListCellRenderer render = new DefaultListCellRenderer(false);
    render.setUIID("MyAutoCompleteList");
    return render;
}