【问题标题】:TextField background transparency in Codenameone when graphics background图形背景时 Codenameone 中的 TextField 背景透明度
【发布时间】:2018-08-15 05:53:02
【问题描述】:

我的问题是我有一个带有 2 色背景的表单;在顶部,我有一个 bg 透明文本字段。当它在模拟器中渲染时,它看起来很好,因为 TextField 位于背景中颜色相遇的点(根据字段 2)。

但是当我单击字段 3 时,文本字段会呈现一个只有我的一种背景颜色的纯色背景列,而我希望它保持透明。

背景由深蓝色的 LayeredLayout 组成,然后我在下半部分有一个浅蓝色图形:

class RectangleComponent extends Component {

private int bottomColour;

protected void setBottomColour(int colour) {
    bottomColour = colour;
}

@Override
protected Dimension calcPreferredSize() {
    return new Dimension(250, 250);
}

@Override
public void paint(Graphics g) {
    g.setColor(bottomColour);
    int[] int_x = new int[] { 0, getWidth(), getWidth(), 0 };
    int[] int_y = new int[] { (int) (getHeight() / 2.5), ((int) (getHeight() / 2.5)) + 150, getHeight(),
            getHeight() };

    g.fillPolygon(int_x, int_y, 4);
}

我的文本字段是:

public class TextCustom extends TextField {

public TextCustom(String hint, String controlName, int maxChars) {
    Border border = Border.createCompoundBorder(null, Border.createLineBorder(1, 0xffffff), null, null);
    setName(controlName);
    setUIID("v2_Label11LightPadMarg");
    getAllStyles().setBorder(border);
    setHint(hint);
    getHintLabel().setUIID("v2_Label11LightPadMarg");
    getHintLabel().getAllStyles().setFgColor(0xffffff);
    getHintLabel().getAllStyles().setBgTransparency(0);
    getHintLabel().setAlignment(Component.TOP);
    getAllStyles().setBgTransparency(0);
    getAllStyles().setFgColor(0xffffff);
    getSelectedStyle().setBgTransparency(0);

    setCursorPosition(0);
    setMaxSize(maxChars);
    setColumns(maxChars);
    getAllStyles().setMarginLeft(20);
    getAllStyles().setMarginRight(20);
}

}

谢谢

【问题讨论】:

    标签: java codenameone


    【解决方案1】:

    看起来这是模拟器的问题。在安卓设备上看起来不错。结束。

    【讨论】:

    • 很难创建一种可移植的方式来透明地编辑,因为某些平台的 UI 在这种情况下会留下伪影。我们尽力而为,但在某些情况下,它只是退回到标准颜色
    • 所以你是说你不能保证它可以在所有设备上运行?我只有一组有限的安卓和苹果设备可供测试。如果你不能,那么我将不得不退出构建该背景的工作,并通过主题应用 PNG 背景。干杯
    • 我不确定 PNG 对于这些设备是否会更好。这是编辑过程中透明度概念的问题。我认为你不需要重写来支持边缘情况。
    猜你喜欢
    • 2011-11-10
    • 2020-12-19
    • 1970-01-01
    • 2017-08-11
    • 2020-02-10
    • 2022-01-23
    • 2018-01-07
    • 2018-02-12
    • 2011-10-24
    相关资源
    最近更新 更多