Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Created February 7, 2020 07:55
Show Gist options
  • Save pyeongho/44f8bd5cac7c26a9d6110550535cbefa to your computer and use it in GitHub Desktop.
Save pyeongho/44f8bd5cac7c26a9d6110550535cbefa 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
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