Resolved color instead of a resource id

前端 未结 6 884
名媛妹妹
名媛妹妹 2020-12-14 06:02

Recently I\'ve seen appeared a lint error in my code:

Should pass resolved color instead of resource id here: getResources().getColor(R.color.maps_l

6条回答
  •  天命终不由人
    2020-12-14 06:23

    Since getResources().getColor() is deprecated, you need to do this to get the color:

    int color = ContextCompat.getColor(getContext(),your_color_id);
    

    Now you have the color with respect to the current context Set the color using:

    your_view.setBackgroundColor(color);
    

提交回复
热议问题