using WebView in Android version 5.x May report the following error
android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.WebView
solution 1:
use createConfigurationContext () method to get the Context p>
public class LollipopFixedWebView extends WebView {
public LollipopFixedWebView(Context context) {
super(getFixedContext(context));
}
public LollipopFixedWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
}
public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
}
public static Context getFixedContext(Context context) {
// Android Lollipop 5.0 & 5.1
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT <= 22)
return context.createConfigurationContext(new Configuration());
return context;
}
}
solution 2:
in the build.gradle of the project, appcompat version 1.1.0 May be buggy, use the following version to solve the problem
implementation 'androidx.appcompat:appcompat:1.2.0'
p>
div>
Read More:
- Android error reporting: error inflating class android.webkit.WebView
- Android WebView loading HTTP error [How to Solve]
- android studio:Error inflating class android.support.v4.widget.SwipeRefreshLayout
- The local web page in WebView failed to load with XMLHttpRequest
- Error inflating class android.support.v7.widget.SearchView
- Android Studio | Failed to find target with hash string ‘android-26’ in: D:\Android\sdk
- WebView load webpage, HTTP call error
- Solutions to errors in virtual machine running in Android studio
- Android Error | Failed to find target with hash string ”android-23′ in…
- Error in Cordova project execution command after Android studio upgrade: could not find gradle wrapper within Android SDK
- IOS WebView failed to load the web page. Error domain = kcferrodomaincfnetwork code = 310 “there was a problem communicating with the secure web proxy server (HTTPS). “
- Error: Error parsing D:\new_android\Android SDK\system-images\android-25\android-wear\armeabi-v7a\de
- Android learning notes 03: some problems and solutions in the learning process
- Android Studio sync build.gradle appears: Failed to resolve: com.android.support:appcompat problem
- WebView loadrequest request request error “nsurlconnection finished with error – Code – 1022”
- As Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject.
- [Solved] Android Gradle configure error: Location: Class buildconfig
- Install of Android studio_ FAILED_ OLDER_ Solutions to SDK
- 【PTA:】 Error: class X is public should be declared in a file named X.java
- Failed to find target with hash string ‘android-25’ in:D:\SDK