资源获取¶
findByContext¶
findByContext
为你提供了 Context 以便你查找对应的资源。
val drawable = findByContext {
AppCompatResources.getDrawable(this, R.drawable.android_logo)
}
try {
drawable = ResUtilsKt.findByContext(context ->
AppCompatResources.getDrawable(context, R.drawable.android_logo)
);
} catch (Exception e) {
throw new RuntimeException(e);
}
findByResources¶
findByResources
为你提供了 Resources 以便你查找对应的资源。
val drawable = findByResources { res, theme ->
ResourcesCompat.getDrawable(res, R.drawable.android_logo, theme)
}
try {
drawable = ResUtilsKt.findByResources((resources, theme) ->
ResourcesCompat.getDrawable(resources, R.drawable.android_logo, theme)
);
} catch (Exception e) {
throw new RuntimeException(e);
}