【发布时间】:2021-06-11 04:01:01
【问题描述】:
我是 android 新手,我的回收站视图有问题。我希望使用随机颜色作为个人资料图像背景,但是当我上下滑动几次时颜色会不断变化,我希望每个项目都保持特定的颜色。请问我怎样才能做到这一点。这是我为随机化颜色所做的:
private fun changeClientProfileBackgroundColor ():Drawable?{val colorDrawables = arrayOf(
R.drawable.client_list_background_color_drawable_1,
R.drawable.client_list_background_color_drawable_2,
R.drawable.client_list_background_color_drawable_3,
R.drawable.client_list_background_color_drawable_4,
R.drawable.client_list_background_color_drawable_5,
R.drawable.client_list_background_color_drawable_6 )return ContextCompat.getDrawable(
context!!, colorDrawables[(Math.random() * 5).roundToInt()])}
binding.clientHomeImageProfileColorBackground.background =
changeClientProfileBackgroundColor()
Image of the recycler view with the background random colors
【问题讨论】:
标签: android android-studio kotlin android-recyclerview