Android 支持库中的 ActionBar#setDefaultDisplayHomeAsUpEnabled 是什么?

are*_*naq 5 android android-actionbar android-support-library

我知道有什么setDisplayHomeAsUpEnabled作用,但setDefaultDisplayHomeAsUpEnabled我只能想知道什么是为了。没有找到文档,除了正在使用之外找不到任何东西。

Pho*_*oca 5

此方法仅在 Support Action Bar 中可用,在自 Android 3 以来可用的“原生”ActionBar 类中不可用。更重要的是,它@hide在源代码中被注释,这意味着它不是第三方开发人员的官方 API 的一部分。这就是为什么谷歌没有记录的原因。你不应该使用它。

对来源进行了深入研究,我发现该方法在WindowDecorActionBar以下位置实现:

public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
    if (!mDisplayHomeAsUpSet) {
        setDisplayHomeAsUpEnabled(enable);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以基本上它与 using 完全相同setDisplayHomeAsUpEnabled,但前提是尚未使用所述函数手动设置该值。

tldr:您应该始终使用setDisplayHomeAsUpEnabled并忽略默认方法。