Created
February 7, 2020 07:55
-
-
Save pyeongho/44f8bd5cac7c26a9d6110550535cbefa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
class LollipopFixedWebView : WebView { | |
constructor(context: Context) : super( | |
getFixedContext( | |
context | |
) | |
) { | |
} | |
constructor(context: Context, attrs: AttributeSet?) : super( | |
getFixedContext(context), | |
attrs | |
) { | |
} | |
constructor( | |
context: Context, | |
attrs: AttributeSet?, | |
defStyleAttr: Int | |
) : super(getFixedContext(context), attrs, defStyleAttr) { | |
} | |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
constructor( | |
context: Context, | |
attrs: AttributeSet?, | |
defStyleAttr: Int, | |
defStyleRes: Int | |
) : super( | |
getFixedContext(context), | |
attrs, | |
defStyleAttr, | |
defStyleRes | |
) { | |
} | |
companion object { | |
private fun getFixedContext(context: Context): Context { | |
return if (Build.VERSION.SDK_INT in 21..22) context.createConfigurationContext( | |
Configuration() | |
) else context | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment