是否可以在Java ME中自定义标题栏?
答案 0 :(得分:1)
您可能想查看J2ME Polish,它为MIDlet提供了大量的UI自定义,包括标题栏:link text
答案 1 :(得分:0)
API不提供自定义默认标题栏的功能,但我们可以尝试编写自己的栏。这本身就是对UI约定的轻微违反。有些手机允许我们使用setTitle(null)
删除标题。 Java移动工具包中的手机就是这样的,但Series 40和60仿真器似乎不支持这种情况,而是生成默认标题。另一方面,我测试的Sony Ericssons和Motorolas似乎支持这一点。
但是,我们可以检测是否存在删除标题栏的功能。我们不使用sizeChanged
回调,因为当画布不可见时,可能会延迟调用此函数。相反,我们在删除栏之前和之后都会调用getHeight
。根据规范,getHeight
应始终返回正确的最新值,即使未显示画布也是如此。以下是实现检测的代码:
public static boolean HIDE_TITLE_ENABLED;//Whether the implementation allows us to hide the title bar
static{
//See if we can remove the title by ensuring it is non-nil, then attempting
//to remove it. If we can't, then reset it.
Canvas c=new Canvas(){
protected void paint(Graphics g){
}
};
c.setTitle("test");
int preHeight=c.getHeight();
c.setTitle(null);
int afterHeight=c.getHeight();
HIDE_TITLE_ENABLED=preHeight!=afterHeight;
}
也可以使用全屏模式隐藏标题栏,但这也隐藏了其他元素。这种方法在游戏中很受欢迎。