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

前端 未结 11 1992
我寻月下人不归
我寻月下人不归 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:27

    In Kotlin, you can do:

    ContextCompat.getColor(requireContext(), R.color.stage_hls_fallback_snackbar)
    

    if requireContext() is accessible from where you are calling the function. I was getting an error when trying

    ContextCompat.getColor(context, R.color.stage_hls_fallback_snackbar)
    

提交回复
热议问题