AndroidManifest的activity标签中配置的theme属性的生效流程

AndroidManifest的activity标签中配置的theme属性的生效流程大体如下:
1.android.content.pm.PackageParser.parseActivity()接口中读取AndroidManifest的activity标签中配置的theme属性,代码如下:

a.info.theme = sa.getResourceId(R.styleable.AndroidManifestActivity_theme, 0);

说明:
① a.info为android.content.pm.ActivityInfo对象实例。

2.android.content.pm.ActivityInfo.getThemeResource()接口中获取当前Activity的theme,代码如下:

public final int getThemeResource() {
  return theme != 0 ? theme : applicationInfo.theme;
}

说明:
① 如果当前Activity没有在AndroidManifest中配置theme属性的话,则使用Application的默认theme。

3.android.app.ActivityThread.performLaunchActivity()接口中设置theme,然后调用Activity的onCreate接口,代码如下:

int theme = r.activityInfo.getThemeResource();
if (theme != 0) {
  activity.setTheme(theme);
}

activity.mCalled = false;
if (r.isPersistable()) {
  mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);
} else {
  mInstrumentation.callActivityOnCreate(activity, r.state);
}

说明:
① 在AndroidManifest配置的theme,最终也是调用setTheme()接口生效的。
② mInstrumentation.callActivityOnCreate()接口中调用了Activity的onCreate()接口。
③ 从上述逻辑可见,如果需要在Activity代码中调用setTheme()接口的话,推荐在super.onCreate()接口调用之前。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值