Метод setTint
Метод setTint класса
Drawable
задаёт оттенок для vector и bitmap
иконок. Цвет передают как Int ARGB,
часто из
getColor
для R.color.brand.
Синтаксис
drawable.setTint(colorInt)
Параметры
| Параметр | Описание |
|---|---|
tint |
Цвет в формате ARGB, например
из R.color.brand.
|
Пример
Давайте перекрасим ic_logo в brand:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import com.example.app.R
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val icon = resources.getDrawable(R.drawable.ic_logo, theme)
val brand = resources.getColor(R.color.brand, theme)
icon.setTint(brand)
setContent {
Text(text = "abcde")
}
}
}
На экране текст "abcde",
а иконка в памяти уже перекрашена в brand.
Смотрите также
-
класс
Drawable,
у которого вызывают setTint -
метод
getColor,
откуда берут tint -
функция
colorResource,
Compose-аналог цвета brand -
метод
getDrawable,
которым получают drawable перед tint