您的位置:首页 > 其它

Activity多次调用getActionBar()返回的是同一个ActionBar对象吗?

2012-08-20 14:39 239 查看
在应用程序开发中,经常看到在Activity中多次调用getActionBar()方法,然后对直接对其进行设置,

次数多了,我不禁想问一句,多次调用getActionBar()并对其进行操作,实际上是用到一个对象了吗?

下面从源码的角度进行分析。

public ActionBar getActionBar() {

initActionBar();

return mActionBar;

}

一看到这,关键的部位出来了,initActionBar(); 继续跟进

private void initActionBar() {

Window window = getWindow();

// Initializing the window decor can change window featureflags.

// Make sure that we have the correct set before performing thetest below.

window.getDecorView();

if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR) ||mActionBar != null) {

return;

}

mActionBar = new ActionBarImpl(this);

}

看到了吧,

if (isChild() || !window.hasFeature(Window.FEATURE_ACTION_BAR)|| mActionBar != null) {

return;

}

当mActionBar不为null的时候,直接返回

所以二者返回的是同一个ActionBar对象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐