Issue
Can anyone tell me the right way of using getDrawable() , I recall last time I used it was just fine with one parameter, but now I am getting this method is deprecated error, anyone? Bellow is the snippet I am trying to use
private void toggleUi() {
ImageView imageView = (ImageView) findViewById(R.id.silent_icon);
Drawable silentImage;
if(silent) {
silentImage = getResources().getDrawable(R.drawable.silent_on);
} else {
silentImage = getResources().getDrawable(R.drawable.silent_off);
}
imageView.setImageDrawable(silentImage);
}
Will be glad if anyone can help thanks.
Solution
Since API 22 you should call ContextCompat.getDrawable(context, R.drawable.***)
instead of getResources().getDrawable(R.drawable.***)
.
You can see the documentation of ContextCompat from the support library for more details.
Answered By - arodriguezdonaire
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.