Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated method #34

Open
YanMESS opened this issue Mar 17, 2018 · 1 comment
Open

Deprecated method #34

YanMESS opened this issue Mar 17, 2018 · 1 comment

Comments

@YanMESS
Copy link

YanMESS commented Mar 17, 2018

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!

@denisk20
Copy link
Collaborator

Thank you for the suggestions! Feel free to open a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants