注解

2020-11-14  本文已影响0人  小虫虫奇遇记

分类

注解声明
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface ContentView {
int value();
}
//注解使用
@ContentView(R.layout.activity_home)
public class HomeActivity extends BaseActivity {
。。。
}
//注解解析
for (Class c = this.getClass(); c != Context.class; c = c.getSuperclass()) {
ContentView annotation = (ContentView) c.getAnnotation(ContentView.class);
if (annotation != null) {
try {
this.setContentView(annotation.value());
} catch (RuntimeException e) {
e.printStackTrace();
}
return;
}

上一篇 下一篇

猜你喜欢

热点阅读