Я столкнулся с этой проблемой, я пробовал много решений, но они не работают.
XML
<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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.jakewharton:butterknife:8.8.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="alertDialogTheme">@style/AppTheme.Dialog.Alert</item>
</style>
<style name="AppTheme.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.TextView" />
<style name="AppTheme.TextView.1" parent="AppTheme.TextView">
<item name="android:textSize">15sp</item>
</style>
<style name="AppTheme.TextView.1.White" parent="AppTheme.TextView.1">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.2" parent="AppTheme.TextView">
<item name="android:textSize">17sp</item>
</style>
<style name="AppTheme.TextView.2.White" parent="AppTheme.TextView.2">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.2.Dark" parent="AppTheme.TextView.2">
<item name="android:textColor">@color/text_dark</item>
</style>
<style name="AppTheme.TextView.3" parent="AppTheme.TextView">
<item name="android:textSize">19sp</item>
</style>
<style name="AppTheme.TextView.3.White" parent="AppTheme.TextView.3">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.Clickable">
<item name="android:background">?attr/selectableItemBackground</item>
<item name="android:padding">@dimen/spacing_small</item>
<item name="android:textAllCaps">true</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppTheme.TextView.Clickable.1" parent="AppTheme.TextView.Clickable">
<item name="android:textSize">15sp</item>
</style>
<style name="AppTheme.TextView.Clickable.1.White" parent="AppTheme.TextView.Clickable.1">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="AppTheme.TextView.Clickable.2" parent="AppTheme.TextView.Clickable">
<item name="android:textSize">17sp</item>
</style>
<style name="AppTheme.TextView.Clickable.2.White" parent="AppTheme.TextView.Clickable.2">
<item name="android:textColor">@android:color/white</item>
</style>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.drawer_layout) DrawerLayout drawerLayout;
@BindView(R.id.drawer) NavigationView navigationView;
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
setupDrawer();
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, ShotListFragment.newInstance())
.commit();
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void setupDrawer() {
drawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.string.open_drawer, /* "open drawer" description */
R.string.close_drawer /* "close drawer" description */
);
drawerLayout.addDrawerListener(drawerToggle);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (item.isChecked()) {
drawerLayout.closeDrawers();
return true;
}
Fragment fragment = null;
switch (item.getItemId()) {
case R.id.drawer_item_home:
fragment = ShotListFragment.newInstance();
setTitle(R.string.title_home);
break;
case R.id.drawer_item_likes:
fragment = ShotListFragment.newInstance();
setTitle(R.string.title_likes);
break;
case R.id.drawer_item_buckets:
fragment = BucketListFragment.newInstance();
setTitle(R.string.title_buckets);
break;
}
drawerLayout.closeDrawers();
if (fragment != null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
return true;
}
return false;
}
});
}
}
Вышло три исключения, как показано ниже: Причина:
android.view.InflateException: строка двоичного XML-файла # 24: двоичный XML
Строка файла № 24: Ошибка надувания класса
android.support.design.widget.NavigationView
Буду признателен за любую помощь!