如何将可提取资产作为整数返回?

问题描述 投票:0回答:1

在我的应用程序中,我正在使用此功能来返回更改颜色的Drawable女巫:

fun setDrawableColor(icon: Drawable, color: Int): Drawable {
    val drawable = DrawableCompat.wrap(icon)
    DrawableCompat.setTint(drawable, getColor(color))
    return drawable
}

这很好用。但是,我不能将其用于setIcon()AlertDialog,因为它像这样DrawablesetIcon(R.dawable.my_icon)作为整数。

我需要类似上面的函数,该函数执行完全相同的操作,但返回Drawable作为Integer。我该如何实现?

谢谢!

<<

您到底想要什么?我们已经有setIcon(Drawable)的方法AlertDialog。无法在此处返回Integer,因为Drawable as an Integer仅在编译时创建。(drawable的ID)。
android kotlin android-drawable
1个回答
-1
投票
© www.soinside.com 2019 - 2024. All rights reserved.