Android支持库中的ActionBar#setDefaultDisplayHomeAsUpEnabled是什么? [英] What does ActionBar#setDefaultDisplayHomeAsUpEnabled in Android Support library?
问题描述
我知道setDisplayHomeAsUpEnabled
的作用,但是setDefaultDisplayHomeAsUpEnabled
是什么,我只能怀疑.没有找到文档,找不到任何东西,除了正在使用中.
I know what setDisplayHomeAsUpEnabled
does, but what is setDefaultDisplayHomeAsUpEnabled
for I can only wonder. No documentation found, cannot find anything except it is being used.
推荐答案
此方法仅在Support Action Bar中可用,而在从Android 3开始可用的"native" ActionBar类中不可用.更重要的是,它用
This method is only available in the Support Action Bar, not in the "native" ActionBar class available since Android 3. More importantly, it is annotated with @hide
in the source, meaning it is not part of the official API for third-party developers. That is why it is nowhere documented by Google. You should just not use it.
深入研究源代码之后,我发现了在WindowDecorActionBar
中实现的方法:
Having a deeper look into the sources, I found the method implemented in WindowDecorActionBar
:
public void setDefaultDisplayHomeAsUpEnabled(boolean enable) {
if (!mDisplayHomeAsUpSet) {
setDisplayHomeAsUpEnabled(enable);
}
}
因此,基本上它与使用setDisplayHomeAsUpEnabled
完全相同,但前提是尚未使用上述功能手动设置该值.
So basically it does exactly the same as using setDisplayHomeAsUpEnabled
, but only if the value has not yet been set manually using the said function.
tldr:您应该始终使用setDisplayHomeAsUpEnabled
并忽略默认方法.
tldr: you should always use setDisplayHomeAsUpEnabled
and ignore the default method.
这篇关于Android支持库中的ActionBar#setDefaultDisplayHomeAsUpEnabled是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!