BlackBerry RichText格式化

发布于 2024-11-08 16:05:35 字数 1038 浏览 0 评论 0原文

我正在使用 BlackBerry 知识中心教程“如何设置 RichTextField 格式" 为我的 RichTextField 设置格式。

我在格式化文本时遇到了一些困难,例如:

AI在B街上行走突然看到一只会飞的狗

如果我只想加粗字母A和A。 BI 需要有它们的字符串索引和长度。

我创建了2个数组,第一个数组处理整个文本中字母的索引,第二个数组处理每个字母索引的长度,例如:A(长度1),WC(长度2)。

我尝试循环运行它,但它不起作用:

Font fonts[] = new Font[2];
    int[] offset = new int[3];
    byte[] attribute = new byte[3];

    //Get three instances of the default font.
    //On plain, one bold and one bold and italic.
    fonts[0] = Font.getDefault();
    fonts[1] = Font.getDefault().derive(Font.BOLD);

    for (int i = 0; i<lettersLength; i++) {
      offset[0] = letterIndexes[i]; //handles the indexes of the letters in the entire text
      attribute[0] = 1;
      offset[1] = letterLength[i]; //handles each letter index
    }

I am using the BlackBerry knowledge center tutorial "How To Format RichTextField" to set a format for my RichTextField.

I encountered some difficulty when formatting text like:

A I was walking in the street B suddenly I saw a flying dog

If I want to bold only the letters A & B I need to have their string indexes and length.

I created 2 arrays, one handles the indexes of the letters in the entire text and the second array handles the length of each letter index, for example: A (length 1), WC(length 2).

I tried to run it in a loop but it doesn't work:

Font fonts[] = new Font[2];
    int[] offset = new int[3];
    byte[] attribute = new byte[3];

    //Get three instances of the default font.
    //On plain, one bold and one bold and italic.
    fonts[0] = Font.getDefault();
    fonts[1] = Font.getDefault().derive(Font.BOLD);

    for (int i = 0; i<lettersLength; i++) {
      offset[0] = letterIndexes[i]; //handles the indexes of the letters in the entire text
      attribute[0] = 1;
      offset[1] = letterLength[i]; //handles each letter index
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2024-11-15 16:05:35
offsets[0] = 0; // index of A, first character
attribute[0] = 1;  // Choose the bold font starting at offsets[0]
offsets[1] = 1;  // 1 past the desired bold
attributes[1] = 0;  // assign the regular font starting at offset[1]
offsets[2] = index of 'B';
attributes[2] = 1; // set the style to the bold font for this
offsets[3] = index of 'B' + 1; // the new non bold segment starts just after the B
attributes[3] = 0; // set the style to normal

抱歉,没有更好的代码,但希望它有所帮助。

offsets[0] = 0; // index of A, first character
attribute[0] = 1;  // Choose the bold font starting at offsets[0]
offsets[1] = 1;  // 1 past the desired bold
attributes[1] = 0;  // assign the regular font starting at offset[1]
offsets[2] = index of 'B';
attributes[2] = 1; // set the style to the bold font for this
offsets[3] = index of 'B' + 1; // the new non bold segment starts just after the B
attributes[3] = 0; // set the style to normal

Sorry not nicer code, but hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文