-
public final class ResourcesKtxKt
-
-
Method Summary
Modifier and Type Method Description final static StringgetSystemString(@StringRes() Integer stringRes)从系统资源中获取字符串。 通常用于获取Android系统定义的标准字符串。 final static StringgetSystemString(@StringRes() Integer stringRes, Object format)从系统资源中获取格式化后的字符串。 通常用于获取Android系统定义的标准字符串,并进行参数格式化。 final static StringgetResourcesString(@StringRes() Integer stringRes)从应用程序资源中获取字符串。 用于获取当前应用程序定义的字符串资源。 final static StringgetResourcesString(@StringRes() Integer stringRes, Object format)从应用程序资源中获取格式化后的字符串。 用于获取当前应用程序定义的字符串资源,并进行参数格式化。 final static DrawablegetResourcesDrawable(@DrawableRes() Integer drawableRes)从应用程序资源中获取 Drawable 对象,考虑主题兼容性。 此函数使用全局的 application resources 和 theme 来获取 Drawable,以确保与主题的兼容性。 final static DrawablegetContextDrawable(@DrawableRes() Integer drawableRes)从应用程序上下文中获取 Drawable 对象。 此函数使用全局的 application context 来获取 Drawable,适用于不需要考虑主题兼容性的情况。 final static IntegergetResourcesColor(@ColorRes() Integer colorRes)根据资源ID从应用程序资源中获取颜色值,考虑主题属性。 此函数使用全局的application资源和主题来获取颜色,以确保与主题的兼容性。 final static IntegergetContextColor(@ColorRes() Integer colorRes)从应用程序上下文中获取颜色值。 此函数使用全局的application上下文来获取颜色,适用于不需要考虑主题兼容性的情况。 final static ColorStateListgetResourcesColorStateList(@ColorRes() Integer colorRes)根据资源ID从应用程序资源中获取颜色状态列表,考虑主题属性。 此函数使用全局的application资源和主题来获取颜色状态列表,以确保与主题的兼容性。 final static ColorStateListgetContextColorStateList(@ColorRes() Integer colorRes)从应用程序上下文中获取颜色状态列表。 此函数使用全局的application上下文来获取颜色状态列表,适用于不需要考虑主题兼容性的情况。 final static DrawableapplyTint(Drawable $self, Boolean shouldApplyTint, Integer tint)根据条件为 Drawable 应用或移除颜色滤镜(tint)。此函数允许开发者根据 shouldApplyTint 参数决定是否为 Drawable 应用颜色滤镜。如果 shouldApplyTint 为 true, 则使用指定的 tint 颜色值应用颜色滤镜;如果为 false,则移除任何已应用的颜色滤镜。 颜色滤镜的应用方式根据 Android 系统版本决定,Android 10(API 级别 29,Q)及以上版本使用 BlendModeColorFilter, 低版本使用 setColorFilter 方法结合 PorterDuff.Mode.SRC_IN 模式。 final static DrawableapplySize(Drawable $self, Integer width, Integer height)为 Drawable 设置尺寸,并保持原始宽高比。此函数允许开发者为 Drawable 设置新的宽度和高度。如果只指定了一个维度(宽度或高度),函数会根据 Drawable 的原始宽高比计算缺失的维度。 如果没有指定有效的宽度或高度(即两者都小于或等于0),则重置为 Drawable 的固有尺寸。 final static BitmapensureBitmapCanDraw(Bitmap $self)final static Bitmapscreenshot(View $self)-
-
Method Detail
-
getSystemString
final static String getSystemString(@StringRes() Integer stringRes)
从系统资源中获取字符串。 通常用于获取Android系统定义的标准字符串。
- Parameters:
stringRes- 字符串资源的ID。
-
getSystemString
final static String getSystemString(@StringRes() Integer stringRes, Object format)
从系统资源中获取格式化后的字符串。 通常用于获取Android系统定义的标准字符串,并进行参数格式化。
- Parameters:
stringRes- 字符串资源的ID。format- 用于格式化字符串的参数列表。
-
getResourcesString
final static String getResourcesString(@StringRes() Integer stringRes)
从应用程序资源中获取字符串。 用于获取当前应用程序定义的字符串资源。
- Parameters:
stringRes- 字符串资源的ID。
-
getResourcesString
final static String getResourcesString(@StringRes() Integer stringRes, Object format)
从应用程序资源中获取格式化后的字符串。 用于获取当前应用程序定义的字符串资源,并进行参数格式化。
- Parameters:
stringRes- 字符串资源的ID。format- 用于格式化字符串的参数列表。
-
getResourcesDrawable
final static Drawable getResourcesDrawable(@DrawableRes() Integer drawableRes)
从应用程序资源中获取 Drawable 对象,考虑主题兼容性。 此函数使用全局的 application resources 和 theme 来获取 Drawable,以确保与主题的兼容性。
- Parameters:
drawableRes- Drawable 资源的 ID。
-
getContextDrawable
final static Drawable getContextDrawable(@DrawableRes() Integer drawableRes)
从应用程序上下文中获取 Drawable 对象。 此函数使用全局的 application context 来获取 Drawable,适用于不需要考虑主题兼容性的情况。
- Parameters:
drawableRes- Drawable 资源的 ID。
-
getResourcesColor
final static Integer getResourcesColor(@ColorRes() Integer colorRes)
根据资源ID从应用程序资源中获取颜色值,考虑主题属性。 此函数使用全局的application资源和主题来获取颜色,以确保与主题的兼容性。
- Parameters:
colorRes- 颜色资源的ID。
-
getContextColor
final static Integer getContextColor(@ColorRes() Integer colorRes)
从应用程序上下文中获取颜色值。 此函数使用全局的application上下文来获取颜色,适用于不需要考虑主题兼容性的情况。
- Parameters:
colorRes- 颜色资源的ID。
-
getResourcesColorStateList
final static ColorStateList getResourcesColorStateList(@ColorRes() Integer colorRes)
根据资源ID从应用程序资源中获取颜色状态列表,考虑主题属性。 此函数使用全局的application资源和主题来获取颜色状态列表,以确保与主题的兼容性。
- Parameters:
colorRes- 颜色状态列表资源的ID。
-
getContextColorStateList
final static ColorStateList getContextColorStateList(@ColorRes() Integer colorRes)
从应用程序上下文中获取颜色状态列表。 此函数使用全局的application上下文来获取颜色状态列表,适用于不需要考虑主题兼容性的情况。
- Parameters:
colorRes- 颜色状态列表资源的ID。
-
applyTint
final static Drawable applyTint(Drawable $self, Boolean shouldApplyTint, Integer tint)
根据条件为 Drawable 应用或移除颜色滤镜(tint)。
此函数允许开发者根据 shouldApplyTint 参数决定是否为 Drawable 应用颜色滤镜。如果 shouldApplyTint 为 true, 则使用指定的 tint 颜色值应用颜色滤镜;如果为 false,则移除任何已应用的颜色滤镜。 颜色滤镜的应用方式根据 Android 系统版本决定,Android 10(API 级别 29,Q)及以上版本使用 BlendModeColorFilter, 低版本使用 setColorFilter 方法结合 PorterDuff.Mode.SRC_IN 模式。
- Parameters:
shouldApplyTint- 是否应用颜色滤镜的布尔值,默认为 true。tint- 要应用的颜色值,默认为透明(Color.TRANSPARENT)。
-
applySize
final static Drawable applySize(Drawable $self, Integer width, Integer height)
为 Drawable 设置尺寸,并保持原始宽高比。
此函数允许开发者为 Drawable 设置新的宽度和高度。如果只指定了一个维度(宽度或高度),函数会根据 Drawable 的原始宽高比计算缺失的维度。 如果没有指定有效的宽度或高度(即两者都小于或等于0),则重置为 Drawable 的固有尺寸。
- Parameters:
width- 要设置的宽度,或 null 如果不更改宽度。height- 要设置的高度,或 null 如果不更改高度。
-
ensureBitmapCanDraw
final static Bitmap ensureBitmapCanDraw(Bitmap $self)
-
screenshot
final static Bitmap screenshot(View $self)
-
-
-
-