Resources¶
Extensions to get resources like strings, colors or drawables easily, with support for themed attributes.
Content¶
All the extensions of this module are currently available on
Context, Fragment and View types.
Each one also has an app prefixed version (e.g. appColor(…)) that is
available everywhere but only returns the resources using the
application Context, which means they will not use the theme of the
current Activity.
Colors¶
color(…)takes a color resource id and returns a colorIntcolorSL(…)takes a color resource id and returns aColorStateListstyledColor(…)takes a color theme attribute and returns aIntstyledColorSL(…)takes a color theme attribute and returns aColorStateList
Example¶
val brandPrimaryColor = color(R.color.brand_primary)
val accentColor = styledColor(R.attr.colorAccent)
Dimensions¶
dimen(…)takes a dimension resource id and returns itsFloatvaluedimenPxSize(…)takes a dimension resource id and returns its roundedIntvaluedimenPxOffset(…)takes a dimension resource id and returns its truncatedIntvalue
Like for colors, there are styled prefixed versions that take
a theme attribute.
Drawables¶
drawable(…)takes a drawable resource id and returns aDrawable?styledDrawable(…)takes a drawable theme attribute and returns aDrawable?
Primitives¶
bool(…)takes a boolean resource id and returns itsBooleanvalueint(…)takes an integer resource id and returns itsIntvalueintArray(…)takes an integer array resource id and returns anIntArray
There are styledBool and styledInt that take a theme attribute.
Text¶
txt(…)takes a string resource id and returns aCharSequencestr(…)takes a string resource id and returns aString. There’s also optional format arguments.qtyTxt(…)(for plurals) returns aCharSequenceqtyStr(…)(for plurals) returns aString. There’s also optional format arguments.txtArray(…)takes an array resource id and returns anArray<out CharSequence>strArray(…)takes an array resource id and returns anArray<String>styledTxt(…)takes a string theme attribute and returns aCharSequence?styledStr(…)takes a string theme attribute and returns aString?There’s also optional format arguments.styledTxtArray(…)takes an array theme attribute and returns anArray<out CharSequence>?
Download¶
implementation "com.louiscad.splitties:splitties-resources:2.1.1"