【问题标题】:Inflate exception occurs 'androidx.appcompat:appcompat:1.1.0'发生膨胀异常 'androidx.appcompat:appcompat:1.1.0'
【发布时间】:2020-01-18 00:09:00
【问题描述】:

我正在尝试升级我的 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。但我真的希望有一个代码可以解决问题,对于不更新 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"
    />

我的活动:

 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。

【问题讨论】:

标签: java android android-studio webview android-appcompat


【解决方案1】:

如果您不依赖 DayNight 主题切换(或其他 UiMode events),您可以将 android:configChanges="uiMode" 添加到 webview 活动清单中,以防止 AppCompatDelegate 更新资源配置,从而弄乱 webview 膨胀。在 1.1.0-rc01 到 1.1.0 的更改中,studing the sourcecode 发现了这个解决方法。

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

【讨论】:

  • 精彩而优雅的答案。
猜你喜欢
  • 1970-01-01
  • 2019-08-05
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
相关资源
最近更新 更多