2
2
3
3
package androidx.appcompat.app
4
4
5
+ import android.annotation.SuppressLint
5
6
import android.content.Context
6
7
import android.os.Build
7
8
import android.util.AttributeSet
@@ -10,6 +11,9 @@ import android.view.LayoutInflater
10
11
import android.view.View
11
12
import android.webkit.WebView
12
13
import android.widget.SearchView
14
+ import androidx.appcompat.widget.AlertDialogLayout
15
+ import androidx.appcompat.widget.ButtonBarLayout
16
+ import androidx.appcompat.widget.DialogTitle
13
17
import androidx.core.view.LayoutInflaterCompat
14
18
import dev.b3nedikt.viewpump.InflateRequest
15
19
import dev.b3nedikt.viewpump.InflateResult
@@ -87,6 +91,13 @@ class ViewPumpAppCompatDelegate @JvmOverloads constructor(
87
91
view = createCustomWebView(view, context, attrs)
88
92
}
89
93
94
+ // On Android P normally inflated dialog views crash when used in dialogs
95
+ // opened from web views, we therefor replace them with their newer versions
96
+ // from androidx
97
+ if (Build .VERSION .SDK_INT == Build .VERSION_CODES .P ) {
98
+ view = createDialogWidgetView(name, view, attrs)
99
+ }
100
+
90
101
// The framework SearchView needs to be inflated manually,
91
102
// as it is not inflated by the AppCompatViewInflater
92
103
if (name == " SearchView" ) {
@@ -155,4 +166,27 @@ class ViewPumpAppCompatDelegate @JvmOverloads constructor(
155
166
156
167
private fun createWebViewContext (context : Context ) =
157
168
super .attachBaseContext2(WebViewContextWrapper (context))
169
+
170
+ @SuppressLint(" RestrictedApi" )
171
+ private fun createDialogWidgetView (
172
+ name : String ,
173
+ view : View ? ,
174
+ attrs : AttributeSet
175
+ ): View ? {
176
+
177
+ val wrappedContext = baseDelegate.attachBaseContext2(baseContext)
178
+
179
+ return when (name) {
180
+ " com.android.internal.widget.AlertDialogLayout" ->
181
+ AlertDialogLayout (wrappedContext, attrs)
182
+
183
+ " com.android.internal.widget.DialogTitle" ->
184
+ DialogTitle (wrappedContext, attrs)
185
+
186
+ " com.android.internal.widget.ButtonBarLayout" ->
187
+ ButtonBarLayout (wrappedContext, attrs)
188
+
189
+ else -> view
190
+ }
191
+ }
158
192
}
0 commit comments