【问题标题】:CodenameOne - Getting the text size inside TextViews or TextAreasCodenameOne - 获取 TextViews 或 TextAreas 中的文本大小
【发布时间】:2021-08-16 19:48:19
【问题描述】:

我的 CodenameOne 应用在布局中有一个 BrowserComponent(它是一个 WebView)。

它还有其他组件,例如 TextFields。

我需要 BrowserComponent 中的文本与 TextFields 中的文本大小相同(默认值)。

我使用 CSS font-size 属性在 HTML 中的 BrowserComponent 中设置文本大小。

我试过这条指令:

int size=textField.getStyle().getFont().getSize();

然后创建 HTML,在合适的标签定义中有这个字符串:

"style=\"font-size:"+String.valueOf(size)+"px;\"";

但结果为 0。

是否有可能通过任何方法得到正确的数字?

【问题讨论】:

    标签: java webview codenameone textfield font-size


    【解决方案1】:

    首先:您应该在 getFont() 之前使用 getUnselectedStyle() 而不是 getStyle()

    getSize() 方法适用于the docs 中解释的系统字体。你得到了SIZE_MEDIUM 的回复,这不是你想要的。

    在getFont() 之后尝试getHeight()getPixelSize()

    【讨论】:

      猜你喜欢
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      相关资源
      最近更新 更多