Fix webview crashing in api 21
This commit is contained in:
parent
96cfc4b4c1
commit
d7dad43928
|
@ -0,0 +1,28 @@
|
|||
package org.mariotaku.twidere.view
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.webkit.WebView
|
||||
|
||||
private fun Context.fixForLollipop(): Context {
|
||||
return if (Build.VERSION.SDK_INT in 21..22) {
|
||||
applicationContext
|
||||
} else this
|
||||
}
|
||||
|
||||
class LollipopFixWebView: WebView {
|
||||
|
||||
constructor(context: Context?) : super(context?.fixForLollipop())
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context?.fixForLollipop(), attrs)
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context?.fixForLollipop(), attrs, defStyleAttr)
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context?.fixForLollipop(), attrs, defStyleAttr, defStyleRes)
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, privateBrowsing: Boolean) : super(context?.fixForLollipop(), attrs, defStyleAttr, privateBrowsing)
|
||||
|
||||
init {
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
<org.mariotaku.twidere.view.LollipopFixWebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
|
Loading…
Reference in New Issue