You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
LayoutInflater: support android:theme attribute
This commit is contained in:
@@ -1229,7 +1229,7 @@ public class Resources {
|
|||||||
* @param other The existing Theme to copy from.
|
* @param other The existing Theme to copy from.
|
||||||
*/
|
*/
|
||||||
public void setTo(Theme other) {
|
public void setTo(Theme other) {
|
||||||
themeMap = other.themeMap;
|
themeMap = new HashMap<>(other.themeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,11 +2,26 @@ package android.view;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
public class ContextThemeWrapper extends ContextWrapper {
|
public class ContextThemeWrapper extends ContextWrapper {
|
||||||
|
|
||||||
|
private Resources.Theme theme = getResources().newTheme();
|
||||||
|
|
||||||
public ContextThemeWrapper(Context context, int themeResId) {
|
public ContextThemeWrapper(Context context, int themeResId) {
|
||||||
super(context);
|
super(context);
|
||||||
|
theme.setTo(context.getTheme());
|
||||||
|
setTheme(themeResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTheme(int resid) {
|
||||||
|
theme.applyStyle(resid, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resources.Theme getTheme() {
|
||||||
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package android.view;
|
package android.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -42,7 +43,14 @@ public class LayoutInflater {
|
|||||||
|
|
||||||
Constructor constructor = view_class.getConstructor(Context.class, AttributeSet.class);
|
Constructor constructor = view_class.getConstructor(Context.class, AttributeSet.class);
|
||||||
|
|
||||||
View view_instance = (View)constructor.newInstance(Context.this_application, attrs);
|
Context context = Context.this_application;
|
||||||
|
final TypedArray ta = context.obtainStyledAttributes(attrs, new int[]{com.android.internal.R.attr.theme});
|
||||||
|
final int themeResId = ta.getResourceId(0, 0);
|
||||||
|
if (themeResId != 0) {
|
||||||
|
context = new ContextThemeWrapper(context, themeResId);
|
||||||
|
}
|
||||||
|
ta.recycle();
|
||||||
|
View view_instance = (View)constructor.newInstance(context, attrs);
|
||||||
|
|
||||||
return view_instance;
|
return view_instance;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user