LayoutInflator: support <include/> tags

This commit is contained in:
Julian Winkler
2023-08-06 14:32:28 +02:00
parent 6b79adb2c3
commit 5c6b83e8f1
2 changed files with 16 additions and 3 deletions

View File

@@ -494,6 +494,9 @@ public final class AssetManager {
return rp;*/
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream(fileName);
if (inStream == null) {
return null;
}
ResXmlDocument resXmlDocument = new ResXmlDocument();
resXmlDocument.readBytes(inStream);
ResXmlPullParser xpp = new ResXmlPullParser();

View File

@@ -188,11 +188,10 @@ public class LayoutInflater {
throw new Exception("<requestFocus /> not supported atm");
// parseRequestFocus(parser, parent);
} else if (name.equals("include")) {
throw new Exception("<include /> not supported atm");
/*if (parser.getDepth() == 0) {
if (parser.getDepth() == 0) {
throw new Exception("<include /> cannot be the root element");
}
parseInclude(parser, parent, attrs);*/
parseInclude(parser, parent, attrs);
} else if (name.equals("merge")) {
throw new Exception("<merge /> must be the root element");
} else if (name.equals("blink")) {
@@ -214,4 +213,15 @@ public class LayoutInflater {
if (finishInflate)
parent.onFinishInflate();
}
private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs) throws Exception {
int layout = attrs.getAttributeResourceValue(null, "layout", 0);
View view = inflate(layout, (ViewGroup)parent, true);
if (view == null)
return;
int id = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "id", 0);
if (id != 0)
view.setId(id);
}
}