Android支持库中的ActionBar#setDefaultDisplayHomeAsUpEnabled是什么? [英] What does ActionBar#setDefaultDisplayHomeAsUpEnabled in Android Support library?

查看:101
本文介绍了Android支持库中的ActionBar#setDefaultDisplayHomeAsUpEnabled是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道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类中不可用.更重要的是,它用表示源代码,这意味着它不是第三方开发人员的官方API的一部分.这就是为什么Google在任何地方都没有记录的原因.您不应该使用它.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆