【发布时间】:2012-04-01 11:58:10
【问题描述】:
目前我的应用程序中有 4 个位图按钮。我希望每个按钮都有类似标签/名称的东西,这样每当有人关注特定按钮时,名称就会出现在屏幕上的某处。它可以在顶部、按钮下方或任何地方都可以。
我该怎么做?我尝试搜索位图按钮字段标签,但没有发现任何真正有用的信息。
【问题讨论】:
标签: blackberry java-me
目前我的应用程序中有 4 个位图按钮。我希望每个按钮都有类似标签/名称的东西,这样每当有人关注特定按钮时,名称就会出现在屏幕上的某处。它可以在顶部、按钮下方或任何地方都可以。
我该怎么做?我尝试搜索位图按钮字段标签,但没有发现任何真正有用的信息。
【问题讨论】:
标签: blackberry java-me
您可以在按钮字段下方放置一个 CustomLabelField。覆盖您的 ButtonFields onFocus(int direction) 和 onUnfocus() 方法。在它们内部调用 CustomLabelField 的 setLabel(String label) 方法
class CustomLabelField extends Field {
String label;
public void setLabel(String label){
this.label = label;
invalidate();
}
protected void layout(int arg0, int arg1) {
setExtent(Display.getWidth, getFont().getHeight());
}
protected void paint(Graphics graphics) {
graphics.setColor(Color.Black);
graphics.drawText(label, 0, 0);
}
}
编辑(在 cmets 之后)
您可以使用此自定义按钮并在其中添加其他功能。我没有尝试这是否有效,但应该可以。
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
public class CustomButtonField extends BitmapField{
private String label = "";
private MainScreen yourScreen;
public CustomButtonField(String label, MainScreen yourScreen) {
super();
this.label = label;
this.yourScreen = yourScreen;
}
protected void onFocus(int direction) {
yourScreen.setTitle(label);
super.onFocus(direction);
}
protected void onUnfocus() {
yourScreen.setTitle("");
super.onUnfocus();
}
}
【讨论】: