跳转至

资源获取

findByContext

Version 0.5.2

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

Version 0.5.2

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);
}