API不提供自定义默认标题栏的功能,但我们可以尝试编写自己的标题栏。这本身就是对UI约定的轻微违反。有些电话允许我们使用
setTitle(null)
删除标题。Java移动工具包中的电话以这种方式运行,但是系列40和60仿真器似乎不支持这一点,而是生成默认标题。另一方面,我测试过的索尼爱立信和摩托罗拉似乎支持这一点。
但是,我们可以检测是否有能力移除车头把。我们不使用
sizeChanged
当画布不可见时,作为此函数调用的回调可能会延迟。相反,我们呼唤
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;
}
也可以使用全屏模式隐藏标题栏,但这也隐藏了其他元素。这种方法在游戏中很流行。