发生膨胀异常 'androidx.appcompat:appcompat:1.1.0'

Inflate exception occurs 'androidx.appcompat:appcompat:1.1.0'

我正在尝试升级我的 gradle。当我将 appcompat 从 1.0.2 更新到 1.1.0 时,我的 webview 在某些手机上不再工作。 (api 21 和 22)。
有没有一种聪明的方法可以升级到 1.1.0 并仍然使 webview 工作。

我得到一个 'android.view.InflateException: Binary XML file line #1: Error inflating class '。 我试图找到一种方法来更新我的模拟器上的网络视图。但我真的希望有一个代码可以解决问题,适用于不更新 webview 的用户。

我的xml:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

我的Activity:

 private WebView mWebView;
    private String state;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.login_webview_activity);

            mWebView = findViewById(R.id.webview);

            mWebView.setWebViewClient(new MyBrowser());

            WebSettings settings = mWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setDomStorageEnabled(true);

            CookieManager.getInstance().setAcceptCookie(true);
            CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);

            mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

我的错误:

WebViewActivity: android.view.InflateException: Binary XML file line #1: Error inflating class android.webkit.WebView
        at android.view.LayoutInflater.createView(LayoutInflater.java:633)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at no.posten.sporing.controller.activity.WebViewActivity.onCreate(WebViewActivity.java:53)
        at android.app.Activity.performCreate(Activity.java:5937)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)

再一次 - appcompat 1.0.2 工作得很好,但不是 1.1.0。

如果您不依赖 DayNight 主题切换(或 1.1.0-rc01 到 1.1.0 的其他 UiMode events), you can add android:configChanges="uiMode" to the webview activity manifest to prevent AppCompatDelegate updating the Resources configuration and thereby messing up the webview inflation. Found this workaround by studing the sourcecode 更改。

降级到 1.1.0-rc01 应该也可以。