Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Created February 7, 2020 07:54
Show Gist options
  • Save pyeongho/70dc3d9c1035a9082756f7982059876a to your computer and use it in GitHub Desktop.
Save pyeongho/70dc3d9c1035a9082756f7982059876a to your computer and use it in GitHub Desktop.
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class LollipopFixedWebViewJ extends WebView {
public LollipopFixedWebViewJ(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebViewJ(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebViewJ(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LollipopFixedWebViewJ(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
}
private static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
return context.createConfigurationContext(new Configuration());
return context;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment