I am running this app on sdk version 28. The problem android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
suddenly appeared, causing my app to crash. After checking the nav drawer I know that the problem is when there are menu items to inflate, because when I comment them out the app runs with no problems, i also checked if the problem is with the drawables but I changed them with no effect.
here are my files
manifest.xml file
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/SemiGofaaTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
styles.xml
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <!-- SemiGofaa application theme. --> <style name="SemiGofaaTheme" parent="Theme.AppCompat.NoActionBar"> <!-- Customize your theme here. --> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:colorBackground">@color/colorPrimaryDark</item> <item name="fontFamily">@font/cairo</item> <item name="android:statusBarColor">@color/colorAccent</item> <item name="alertDialogTheme">@style/AlertDialog.AppCompat.Light</item> <item name="android:windowContentTransitions">true</item> <!--<item name="android:background">@drawable/bkg</item>--> </style> <style name="SemiGofaaTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="SemiGofaaTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
build.gradle:
android { compileSdkVersion 28 defaultConfig { applicationId "semicode.semigofaa" minSdkVersion 21 targetSdkVersion 28 versionCode 5 versionName "0.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, // but continue the build even when errors are found: abortOnError false }
MainActivity.java
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_gofaas) { if(userLoggedIn) startActivity(new Intent(this, GofaasActivity.class)); else startActivity(new Intent(this, LoginActivity.class)); } else if (id == R.id.nav_wishlist) { if(userLoggedIn) startActivity(new Intent(this, WishlistActivity.class)); else startActivity(new Intent(this, LoginActivity.class)); } else if (id == R.id.nav_settings) { } else if (id == R.id.nav_terms) { startActivity(new Intent(this,TermsActivity.class)); } else if (id == R.id.nav_contact_us) { }else if (id == R.id.nav_about) { startActivity(new Intent(this,AboutActivity.class)); } else if (id == R.id.nav_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT,getString(R.string.hey_check_out_semigofaa_app) + link); sendIntent.setType("text/plain"); startActivity(sendIntent); }else if(id == R.id.log_out_nav_drawer){ SaveAppData.clearUserData(this); SaveSharedPreference.clearUserData(this); startActivity(new Intent(this,MainActivity.class)); finish(); Toast.makeText(getApplicationContext(),"Logged out",Toast.LENGTH_SHORT).show(); } DrawerLayout drawer = findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
}