ambilwarna
ambilwarna copied to clipboard
Deprecated method
Hi there,
Gradle build indicates this:
warning: [deprecation] removeGlobalOnLayoutListener(OnGlobalLayoutListener) in ViewTreeObserver has been deprecated view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
After some research i came across this solution: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } else { //noinspection deprecation mView.getViewTreeObserver().removeGlobalOnLayoutListener(this); }
https://developer.android.com/reference/android/view/ViewTreeObserver.html#removeGlobalOnLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener)
Another one I found later is: MyView.setBackgroundDrawable(viewAlphaOverlay,gd);
Should be turned into: SetBackground(viewAlphaOverlay,gd);
@SuppressWarnings("deprecation")
private void SetBackground(View MyView, GradientDrawable gd) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN){
MyView.setBackgroundDrawable(gd);
} else {
MyView.setBackground(gd);
}
}
Thanks!
Thank you for the suggestions! Feel free to open a pull request.