Skip to content

Deprecated method #34

@YanMESS

Description

@YanMESS

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions