Skip to content

Commit 644285e

Browse files
committed
@ContentView注解兼容自定义View
1 parent 2592309 commit 644285e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/src/com/lidroid/xutils/ViewUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,13 @@ private static void injectObject(Object handler, ViewFinder finder) {
9191
Class<?> handlerType = handler.getClass();
9292

9393
// inject ContentView
94-
if (Activity.class.isAssignableFrom(handlerType)) {
95-
ContentView contentView = handlerType.getAnnotation(ContentView.class);
96-
if (contentView != null) {
97-
((Activity) handler).setContentView(contentView.value());
94+
ContentView contentView = handlerType.getAnnotation(ContentView.class);
95+
if (contentView != null) {
96+
try {
97+
Method setContentViewMethod = handlerType.getMethod("setContentView", int.class);
98+
setContentViewMethod.invoke(handler, contentView.value());
99+
} catch (Throwable e) {
100+
LogUtils.e(e.getMessage(), e);
98101
}
99102
}
100103

0 commit comments

Comments
 (0)