В моем приложении для Android
gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
в моем основном макете (nav_drawer_main):
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<include
android:id="@+id/mainToolBar"
layout="@layout/tool_bar"/>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="288dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/list_background"
android:choiceMode="singleChoice"
android:divider="@null"
android:listSelector="@drawable/list_selector"
android:paddingLeft="16dip"
android:paddingRight="16dip"/>
</androidx.drawerlayout.widget.DrawerLayout>
и вот мой макет панели инструментов:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolBarConstraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="?android:attr/selectableItemBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:theme="@style/ThemeOverlay.AppCompat.Dark" />
<TextView
android:id="@+id/toolbaTitleTextView"
style="@style/textViewOneLine"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:text="@string/application_name"
app:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="13sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/toolBar"
app:layout_constraintEnd_toEndOf="@+id/toolBar"
app:layout_constraintStart_toStartOf="@+id/toolBar"
app:layout_constraintTop_toTopOf="@+id/toolBar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
В действии:
setContentView(R.layout.nav_drawer_main);
Но я получаю исключение во время выполнения:
E/AndroidRuntime( 4390): FATAL EXCEPTION: main
E/AndroidRuntime( 4390): Process: com.myproject, PID: 4390
E/AndroidRuntime( 4390): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myproject/com.myproject.MainNavigationDrawerFragmentActivity_}: android.view.InflateException: Binary XML file line #8: Binary XML file line #2: Error inflating class layout
E/AndroidRuntime( 4390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
E/AndroidRuntime( 4390): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
E/AndroidRuntime( 4390): at android.app.ActivityThread.-wrap11(ActivityThread.java)
E/AndroidRuntime( 4390): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
E/AndroidRuntime( 4390): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 4390): at android.os.Looper.loop(Looper.java:148)
E/AndroidRuntime( 4390): at android.app.ActivityThread.main(ActivityThread.java:5417)
E/AndroidRuntime( 4390): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4390): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/AndroidRuntime( 4390): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime( 4390): Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #2: Error inflating class layout
E/AndroidRuntime( 4390): at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
E/AndroidRuntime( 4390): at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
E/AndroidRuntime( 4390): at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
E/AndroidRuntime( 4390): at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
E/AndroidRuntime( 4390): at android.app.Activity.setContentView(Activity.java:2172)
E/AndroidRuntime( 4390): at com.myproject.MainNavigationDrawerFragmentActivity_.setContentView(MainNavigationDrawerFragmentActivity_.java:49)
E/AndroidRuntime( 4390): at com.myproject.MainNavigationDrawerFragmentActivity.onCreate(MainNavigationDrawerFragmentActivity.java:252)
E/AndroidRuntime( 4390): at com.myproject.MainNavigationDrawerFragmentActivity_.onCreate(MainNavigationDrawerFragmentActivity_.java:35)
E/AndroidRuntime( 4390): at android.app.Activity.performCreate(Activity.java:6251)
E/AndroidRuntime( 4390): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
E/AndroidRuntime( 4390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
E/AndroidRuntime( 4390): ... 9 more