Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dynamic.apk): ChangeApkContextWrapper的Theme应该克隆BaseContext #1273

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.tencent.shadow.dynamic.apk;

import static android.content.pm.PackageManager.GET_META_DATA;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageInfo;
Expand All @@ -26,8 +28,6 @@
import android.content.res.Resources;
import android.view.LayoutInflater;

import static android.content.pm.PackageManager.GET_META_DATA;

/**
* 修改Context的apk路径的Wrapper。可将原Context的Resource和ClassLoader重新修改为新的Apk。
*/
Expand All @@ -39,6 +39,8 @@ public class ChangeApkContextWrapper extends ContextWrapper {

final private ClassLoader mClassloader;

private Resources.Theme mTheme;

public ChangeApkContextWrapper(Context base, String apkPath, ClassLoader mClassloader) {
super(base);
this.mClassloader = mClassloader;
Expand Down Expand Up @@ -70,7 +72,16 @@ public Resources getResources() {

@Override
public Resources.Theme getTheme() {
return mResources.newTheme();
// 模仿android.view.ContextThemeWrapper#initializeTheme
if (mTheme == null) {
Resources.Theme newTheme = mResources.newTheme();
final Resources.Theme theme = getBaseContext().getTheme();
if (theme != null) {
newTheme.setTo(theme);
}
mTheme = newTheme;
}
return mTheme;
}

@Override
Expand Down
Loading