我正在制作一个应用程序,它有一个来电监听器,然后添加字段直到电话屏幕。 但是,我似乎无法真正控制我使用的标签字段或 PhoneScreenVerticalManager 的宽度。 如果我尝试在 PhoneScreenVerticalManager 上设置边框或背景,则什么也不会发生。 标签字段构造函数中的 USE_ALL_WIDTH 似乎也没有改变任何东西。 并且让标签字段左对齐我也无法开始工作(在标签字段构造函数中尝试了 DrawStyle.Left)。
这是我的代码:
public Incoming(int callId) {
this.callId = callId;
PhoneCall call = Phone.getCall(callId);
String number = call.getPhoneNumber();
Vector contact = ContactUtil.getContactByPhone(number);
screenModel = new ScreenModel(callId);
phoneScreenPortrait = screenModel.getPhoneScreen(PhoneScreen.PORTRAIT, PhoneScreen.INCOMING);
final XYRect rect = screenModel.getDimensions(PhoneScreen.PORTRAIT, PhoneScreen.INCOMING);
PhoneScreenVerticalManager manager = new PhoneScreenVerticalManager()
{
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.setBackgroundColor(Color.WHITE);
g.clear();
super.paint(g);
}
protected void sublayout(int width, int height)
{
super.sublayout(rect.width, height);
super.setExtent(rect.width, height);
}
};
manager.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
manager.setBorder(BorderFactory.createSimpleBorder(new XYEdges(BORDER_PADDING, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING), Border.STYLE_SOLID));
String s = res.getString(FOUND_IN_CONTACTS);
LabelField header = new LabelField(s, LabelField.USE_ALL_WIDTH)
{
protected void layout(int width, int height)
{
super.layout(rect.width, height);
setExtent(rect.width, height);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.setBackgroundColor(Color.WHITE);
g.clear();
super.paint(g);
}
};
header.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
manager.add(header);
LabelField label = new LabelField(contact.firstElement().toString(), LabelField.USE_ALL_WIDTH)
{
protected void layout(int width, int height)
{
super.layout(rect.width, height);
setExtent(rect.width, height);
}
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.setBackgroundColor(Color.WHITE);
g.clear();
super.paint(g);
}
};
label.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
manager.add(label);
phoneScreenPortrait.add(manager);
screenModel.sendAllDataToScreen();
}
任何想法将不胜感激!¡
谢谢
最佳答案
尽管电话屏幕管理器源自字段管理器,但它并不支持所有字段管理器属性。
所以解决方案是设置普通的现场管理器,然后将它们添加到电话屏幕管理器
关于java - PhoneScreenVerticalManager 来电时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8827674/