首页 > 解决方案 > 代号一:隐藏标题(区域)但不隐藏状态栏空间(iOS & Android)

问题描述

我有一个适用于 iOS 和 Android 的应用程序。状态栏没有隐藏。我的主窗体没有标题,没有后​​退命令,工具栏中也没有其他命令。(我所有的其他表单都有一个标题和返回命令。)我想隐藏标题,因为我需要空间。我发现在 iOS 设备上,一个空标题 ("") 可以完成这项工作。但在 Android 设备上却没有;第一次调用 form.show() 时不显示表单内容。如果我们暂停和恢复应用程序,它就会显示出来。Android 实现似乎需要一个非空标题,即使它是隐藏的。

所以我的实现是:

// we use Toolbar.setGlobalToolbar(true)
public class MainForm extends Form {
    public MainForm() {
        super(""); // hides the title area but not the status bar space on iOS
        if (android()) {
            setTitle(" "); // Android needs non-empty title
            getToolbar().hideToolbar(); // hides the title area; don't use on iOS, it removes the status bar space too
        }
        ...

这是一个正确的实现吗?我找不到任何关于此的文档。

在以下评论后编辑:

我也在 ios 上尝试了 getToolbar().setUIID("Container") 的建议。这将删除工具栏顶部填充,因此只剩下状态栏。但是,至少在模拟器中,状态栏的底部不再与 iPhone X 凹槽的底部对齐(它在其上方)。所以我认为填充是必要的,就像在具有标题(和返回命令)的表单上一样。所以我得出以下实现:

// hide title area
super(""); // hides title area on ios (not status bar space and toolbar padding)
if (android()) {
    // hide title area (=toolbar) explicitly
    // use *either* this:
    getToolbar().hideToolbar();        // on ios this also hides the status bar space
    // *or* this:
    getToolbar().setUIID("Container"); // on ios this also hides the Toolbar top padding
}

这个对吗?

标签: androidioscodenameonetoolbartitle

解决方案


推荐阅读