问题
I have an application menu I had created that has been working just fine for over 10 months. I recently created a release and uploaded it to Google for release to my alpha testers. Prior to that I attempted to create a splash screen (Android Splash Screen doesn't display which failed miserably, so I commented out the lines in the manifest in order to create the release and get it out to my testers which is still pending on Google console. I then went back to debug mode and everything went to hell in a hand basket. What a mess. I researched and corrected all the errors I was getting except this one, I simply cannot make the navigation view work.
This is the layout that contains the navigation view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<ViewStub
android:id="@+id/layout_stub"
android:inflatedId="@+id/message_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.75" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
This is nav_header_main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Main Menu"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"/>
</LinearLayout>
This is side_nav_bar:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#FFD700"
android:endColor="#FFD700"
android:startColor="#FFD700"
android:type="linear" />
<!--FFD700 gold 42586E original -->
</shape>
I had removed all code related to the splash screen attempt.
I have no idea why this drawer menu is no longer working. I've looked all over for answers and have found nothing. Why is this all of sudden not working when it had been working right along? What am I missing?
回答1:
One probable solution could be that you're missing the android:layout
attribute which is a reference to the View that will be inflated next to a call of inflate().
Also, you can check the version of your appcompat
library and design support library match.
回答2:
Ok, I figured it out. Seems like the line:
android:theme="@style/AppTheme"
got removed from the manifest:
<application android:allowBackup="true" android:label="Organize My League" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:icon="@mipmap/launchicons">
</application>
I added it back in:
<application android:allowBackup="true" android:label="Organize My League" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:icon="@mipmap/launchicons" android:theme="@style/AppTheme">
</application>
Now the NavigationView inflates properly. Maddening little things like this happen all the time. No idea at what point the theme line disappeared, but it did.
来源:https://stackoverflow.com/questions/60545052/binary-xml-file-line-1-binary-xml-file-line-1-error-inflating-class-android