【问题标题】:Display html text in codenameone在代号中显示 html 文本
【发布时间】:2014-06-27 20:33:43
【问题描述】:

我想将我拥有的 html 格式的文本显示为字符串。 WebBroswer 组件是否支持此功能? 如果是,使用什么方法? 谢谢, 卫生巾

代码:

private void loadCourseDesc() {
    Container courseDescContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    NETextArea title = new NETextArea(AppState.current_Course.getTitle());
    title.setUIID("biggreylabel");
    courseDescContainer.addComponent(title);
    Container c1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
    Label l = new Label("Fees:" + AppState.current_Course.getFees());
    l.setUIID("mgreylabel");
    c1.addComponent(l);
    Label l1 = new Label("Completion Date:" + AppState.current_Course.getExpiryDate());
    l1.setUIID("mgreylabelLM");
    c1.addComponent(l1);
    courseDescContainer.addComponent(c1);
    WebBrowser wb = new WebBrowser(){

        @Override
        public void onLoad(String url) {
            super.onLoad(url); //To change body of generated methods, choose Tools | Templates.
            instance.forceRevalidate();
        }

    };
    wb.setScrollableY(true);
    System.out.println("::---" + AppState.current_Course.getDesc());

    wb.setPage(AppState.current_Course.getDesc(), "http://localhost/");
    courseDescContainer.addComponent(wb);
    replace(courseDescContainer);

替换代码:

private void replace(final Container c) {
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            instance.replaceAndWait(currentCentre, c, null);
            currentCentre = c;
            instance.forceRevalidate();
        }
    });

}

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    它通过将组件添加到容器中来支持它,设置 HTML 而不是 URL,只需使用 setPage 而不是 setURL

    【讨论】:

    • 我实际上在使用 setPage,但它不起作用。包含 Web 浏览器组件的基本容器正在使用淡入淡出转换进行渲染。我删除了过渡,它开始工作。我如何让它与过渡一起工作。我已经用源代码编辑了这个问题。
    • 另外,它适用于模拟器,但不适用于手机。我正在测试 MotoX。它只是显示空白。
    • 您使用的布局是什么?您确定 HTML 对设备有效吗?设备对 HTML 内容的敏感程度远高于桌面。
    • 我正在使用包含不同项目的盒子布局。它还有一个网络浏览器组件。 html内容非常基础。我认为问题在于设备没有在盒子布局中显示 Web 浏览器和其他项目。如果我在中心的边框布局中有网络浏览器,那么它可以工作。可能出了什么问题?
    • 很抱歉没有回过头来,我把它指向我们的 Android 人员,它被埋在那里了。我们需要一些独立的测试用例来重现这个我建议在code.google.com/p/codenameone/issues/list 提交问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多