二进制 XML 错误膨胀类 com.google.android.material.navigation.Navigat



我已经在StackOverflow上进行了广泛的检查,这是一个常见问题,但我未能使用任何解决方案来解决我的问题。我将我的应用程序迁移到 AndoridX,然后我的应用程序在NavigationView上迁移后开始崩溃。但是,如果我注释掉NavigationView的代码,该应用程序运行良好。请查看我所有的xml代码和错误日志。 我已经检查了同一主题的这个相关问题,但我的崩溃没有从答案中解决:

布局代码:

layout_base.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/anchor_view"
android:layout_width="20sp"
android:layout_height="5sp"
android:layout_alignParentRight="true"></View>
</RelativeLayout>
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/layout_tool_bar">
</include>
<RelativeLayout
android:id="@+id/rlt_child_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ll_menu_options"
android:dividerHeight="0.0sp"
android:scrollbars="none" />
<LinearLayout
android:id="@+id/ll_menu_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/iv_powered_by"
android:layout_marginLeft="15dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="15dp"
android:orientation="horizontal"
android:paddingTop="5dp"
android:visibility="gone">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="invisible">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_facebook"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_twitter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="@+id/iv_twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_instagram_page"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="visible">
<ImageView
android:id="@+id/iv_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>
<LinearLayout
android:id="@+id/ll_gplus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="invisible">
<ImageView
android:id="@+id/iv_gplus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/iv_powered_by"
android:layout_width="match_parent"
android:layout_height="9dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="18dp"
android:visibility="gone" />
</RelativeLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

<include layout="@layout/layout_fab"></include>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>

应用程序在此行崩溃:setContentView(R.layout.layout_base_activity);

我也在使用Theme.AppCompat.Light.NoActionBar主题(查看下面的评论(

错误日志:

android.view.InflateException: Binary XML file line #48: Binary XML file line #48: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #48: Binary XML file line #48: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #48: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.pentaloop.playerxtreme.presentation.activities.FileManagerActivity.onCreate(FileManagerActivity.java:155)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)

build.gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
implementation 'com.google.android.gms:play-services-analytics:15.0.2'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'jp.wasabeef:blurry:3.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.satyan:sugar:1.5'
implementation 'info.hoang8f:android-segmented:1.0.6'
implementation 'jcifs:jcifs:1.3.17'
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.jpardogo.googleprogressbar:library:1.2.0'
implementation 'com.github.pwittchen:reactivewifi-rx2:0.3.0'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.6'
implementation 'com.karumi:dexter:5.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.ext.kotlinx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"
//Android X
implementation "androidx.preference:preference:1.0.0"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha07'

}

PS:我已经看了可能的重复问题,答案涉及android.support库。但是,由于我没有在代码中使用支持或设计库,因此该解决方案不适用于我。

DrawerLayout内部,您已经使用了android:drawingCacheQuality="low".当设置为低质量时,图形缓存使用较低的颜色深度,从而失去渲染渐变的精度,因此使用较少的内存。但是android:drawingCacheQuality已被弃用,请参阅此处的官方文档。以编程方式改用 Canvas 和 Pixel API。请参阅此答案 @mostafa-monowar 以实现。

您正在使用Theme.AppCompat.Light.NoActionBar主题。
如入门文档中所述,在您的应用程序中,您必须使用材质组件主题

像这样:

<style name="Theme.MyApp" parent="Theme.MaterialComponents.*">
<!-- ... -->
</style>

使用以下方法之一:

Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar

如果无法将主题更改为从材质组件主题继承,则可以从材质组件主题继承。

相关内容

最新更新