我收到此错误:
android.view.InflateException: Binary XML file line #149: Binary XML file line #149: Error inflating class android.support.design.widget.FloatingActionButton
我知道有一个重复的问题,但是那里的答案不能解决我的问题。
这是我的build.gradle(app)
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 14
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v13:26.1.0'
implementation "com.android.support:support-fragment:26.1.0"
在另一个重复的问题上,答案要求将sdkVersion降级为25。我尝试了一下,但它破坏了我的整个应用程序。我需要在这里和那里添加很多额外的代码,并删除某些功能(例如通知渠道)以使其与SDK 25兼容。
反正还有吗?
我的FAB XML代码:
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_addnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/ic_add_white_24px"
/>
编辑:在完整的目录猫上添加:
09-25 16:20:52.250 5637-5637/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx, PID: 5637
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.OrderActivity}: android.view.InflateException: Binary XML file line #149: Binary XML file line #149: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #149: Binary XML file line #149: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.xxx.xxx.OrderActivity.onCreate(OrderActivity.java:72)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
编辑:按要求添加了其余XML文件。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E0E0E0"
tools:context="com.xxx.xxx.OrderActivity">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/header"
app:layout_constraintLeft_toLeftOf="@+id/ConstraintLayout"
app:layout_constraintRight_toRightOf="@+id/ConstraintLayout"
app:layout_constraintTop_toTopOf="@+id/ConstraintLayout"
android:background="@color/white"
>
<ImageView
android:id="@+id/icon"
style="@style/ThemeOverlay.Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:contentDescription="@string/icon"
android:src="@drawable/local_icon"
app:layout_constraintLeft_toLeftOf="@+id/header"
app:layout_constraintTop_toTopOf="@+id/header"
app:layout_constraintBottom_toBottomOf="@+id/header"
android:layout_marginTop="@dimen/border_margin"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginBottom="@dimen/border_margin"
/>
<TextView
android:id="@+id/org_ID"
style="@style/AppTheme.Subheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
tools:text="ABCD"
android:visibility="visible"
android:layout_marginStart="@dimen/border_margin"
android:layout_marginTop="@dimen/half_border_margin"
app:layout_constraintLeft_toRightOf="@+id/icon"
app:layout_constraintTop_toTopOf="@+id/header"
/>
<TextView
android:id="@+id/user_ID"
style="@style/AppTheme.Subsubheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="35"
android:lines="1"
tools:text="abc123@gmail.com"
android:visibility="visible"
android:layout_marginStart="@dimen/border_margin"
app:layout_constraintLeft_toRightOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/org_ID"/>
<TextView
android:id="@+id/version"
style="@style/AppTheme.Subsubsubheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="30"
android:lines="1"
android:visibility="visible"
android:layout_marginStart="@dimen/border_margin"
app:layout_constraintLeft_toRightOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/user_ID"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more_vert_black_24dp"
android:contentDescription="@string/desc_overflow_button"
android:onClick="showPopup"
app:layout_constraintTop_toTopOf="@+id/header"
app:layout_constraintBottom_toBottomOf="@+id/header"
app:layout_constraintRight_toRightOf="@+id/header"
android:background="@android:color/transparent"
android:layout_marginEnd="@dimen/border_margin2"
/>
</android.support.constraint.ConstraintLayout>
<TextView
android:id="@+id/order_ID"
style="@style/AppTheme.Subheader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/store"
android:visibility="visible"
android:layout_marginStart="@dimen/double_border_margin"
app:layout_constraintBottom_toTopOf="@+id/recycler_orders"
app:layout_constraintLeft_toLeftOf="@+id/ConstraintLayout"
app:layout_constraintTop_toBottomOf="@+id/header" />
<Spinner
android:id="@+id/storespinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/recycler_orders"
app:layout_constraintLeft_toRightOf="@+id/order_ID"
app:layout_constraintTop_toBottomOf="@+id/header"
app:layout_constraintRight_toRightOf="@+id/ConstraintLayout"
android:visibility="visible"
android:layout_marginStart="0dp"
>
</Spinner>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_orders"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/ConstraintLayout"
app:layout_constraintLeft_toLeftOf="@+id/ConstraintLayout"
app:layout_constraintRight_toRightOf="@+id/ConstraintLayout"
app:layout_constraintTop_toBottomOf="@+id/order_ID"
tools:listitem="@layout/item_orders" />
<ProgressBar
android:id="@+id/progress_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/recycler_orders"
android:layout_alignTop="@+id/recycler_orders"
android:layout_centerHorizontal="true"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_addnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/ic_add_white_24px"
/>
</android.support.constraint.ConstraintLayout>
编辑:在styles.xml上添加:
<!-- 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>
</style>
答案 0 :(得分:0)
我已经解决了这个问题。我发现
app:srcCompat="@drawable/ic_add_white_24px"
在我的XML中,可绘制文件位于v24文件夹中,这就是导致错误的原因。
(愚蠢的我)