在Blackberry Display Labelfield中作为链接

时间:2012-03-01 11:49:32

标签: blackberry

如何将labelfield文本显示为链接,它应该是可点击的。例如,我有文本忘记密码,文本应显示为链接。点击它应该转到另一个屏幕。

请提供一些建议或有用的链接.bcoz我是开发黑莓应用程序的新手。

2 个答案:

答案 0 :(得分:3)

您可以使用以下自定义控件。

package com.myapp.controls;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics; 

public class HrefField extends Field {

private String content;
private Font fieldFont;
private int fieldWidth;
private int fieldHeight;
private boolean active = false;
private int backgroundColour = Color.WHITE;
private int textColour = Color.BLACK;
private int[] drawFocusColors;

public HrefField(String content) {
    super(Field.FOCUSABLE);
    this.content = content;
    fieldFont = Font.getDefaultFont();
    fieldWidth = fieldFont.getAdvance(content) + 2;
    fieldHeight = fieldFont.getHeight() + 3;
    drawFocusColors = new int[] { Color.Orange,
            Color.Orange, Color.RED,
            Color.RED};
}

public void setColours(int backgroundColour, int textColour) {
    this.backgroundColour = backgroundColour;
    this.textColour = textColour;
    invalidate();
}

public void setBackgroundColour(int backgroundColour) {
    this.backgroundColour = backgroundColour;
    invalidate();
}

public void setTextColour(int textColour) {
    this.textColour = textColour;
    invalidate();
}

public void setMaskColour() {
    invalidate();
}

public void setFont(Font fieldFont) {
    this.fieldFont = fieldFont;
}

public int getPreferredWidth() {
    return fieldWidth;
}

public int getPreferredHeight() {
    return fieldHeight;
}

protected void layout(int arg0, int arg1) {
    setExtent(getPreferredWidth(), getPreferredHeight());
}

protected void paint(Graphics graphics) {
    int[] X_PTS = new int[] { 0, fieldWidth, fieldWidth, 0 };
    int[] Y_PTS = { 0, 0, fieldHeight, fieldHeight };
    if (active) {
        graphics.drawShadedFilledPath(X_PTS, Y_PTS, null, drawFocusColors,
                null);
    } else {
        graphics.setColor(backgroundColour);
        graphics.fillRect(0, 0, fieldWidth, fieldHeight);
    }

    graphics.setColor(textColour);
    graphics.setFont(fieldFont);
    graphics.drawText(content, 1, 1);
    graphics.drawLine(1, fieldHeight - 2, fieldWidth - 2, fieldHeight - 2);
}

protected boolean navigationClick(int status, int time) {
    fieldChangeNotify(1);
    return true;
}

protected void onFocus(int direction) {
    active = true;
    invalidate();
}

protected void onUnfocus() {
    active = false;
    invalidate();
}
  }

答案 1 :(得分:1)

您可以使用不可编辑的ActiveRichTextField