Android浮动操作按钮在真实设备上失败,但在模拟器中失败

时间:2017-09-11 07:35:09

标签: android android-layout floating-action-button

我面临一个奇怪的问题而不是我不知道如何解决:我已经准备好了一个带浮动操作按钮(fab)的布局。在模拟器中它可以很好地工作,但是当在真实设备中执行我的应用程序时,它会避免运行时异常:

java.lang.RuntimeException: Unable to start activity ComponentInfo{soyacm.es.com.bookgame/soyacm.es.com.bookgame.ui.bookDetail.BookDetailActivity}: android.view.InflateException: Binary XML file line #183: Error inflating class android.support.design.widget.FloatingActionButton
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3150)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
                                                                            at android.app.ActivityThread.access$1000(ActivityThread.java:218)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:145)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6934)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
                                                                         Caused by: android.view.InflateException: Binary XML file line #183: Error inflating class android.support.design.widget.FloatingActionButton
                                                                            at android.view.LayoutInflater.createView(LayoutInflater.java:640)
                                                                            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
                                                                            at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
                                                                            at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
                                                                            at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)

异常将我直接引导到setContentView(R.layout.activity_book_detail);线

模拟器使用Android API24运行,设备使用API​​ 22和API 23运行(均失败)。

这是我在gradle文件中导入的库:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'

我的布局如下(缩小):

<android.support.design.widget.CoordinatorLayout>
    <android.support.v4.widget.NestedScrollView>
       ...
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/read_book_action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        android:src="@drawable/read_book_icon"
        android:backgroundTint="@color/not_so_white_background"
        android:elevation="6dp"
        />
</android.support.design.widget.CoordinatorLayout>

有人找出错误的位置吗?

1 个答案:

答案 0 :(得分:1)

尝试编辑此行.. volumes: name: driver: local driver_opts: type: nfs o: addr=192.168.1.1,rw device: ":/path/to/dir"

android:backgroundTint="@color/not_so_white_background"

<android.support.design.widget.FloatingActionButton
    android:id="@+id/read_book_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="16dp"
    android:src="@drawable/read_book_icon"
    android:backgroundTint="@color/not_so_white_background"
    android:elevation="6dp"
 />