getColor(int id) deprecated on Android 6.0 Marshmallow (API 23)

前端 未结 11 1819
我寻月下人不归
我寻月下人不归 2020-11-22 12:29

The Resources.getColor(int id) method has been deprecated.

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException          


        
11条回答
  •  感情败类
    2020-11-22 13:29

    In Your RecyclerView in Kotlin

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(t: YourObject, listener: OnItemClickListener.YourObjectListener) = with(itemView) {
            textViewcolor.setTextColor(ContextCompat.getColor(itemView.context, R.color.colorPrimary))
            textViewcolor.text = t.name
        }
    }
    

提交回复
热议问题