未使用FAB

时间:2017-08-31 06:24:03

标签: android android-layout

我在布局中使用过fab,但在运行时出现以下错误 08-30 22:01:35.548 26295-26295 /?

  

E / AndroidRuntime:致命异常:主要                                                      处理:com.example.ahr.a1000funnysms,PID:26295                                                      android.view.InflateException:二进制XML文件行#30:错误膨胀类android.support.design.widget.FloatingActionButton                                                          在android.view.LayoutInflater.createView(LayoutInflater.java:620)                                                          在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)                                                          在android.view.LayoutInflater.rInflate(LayoutInflater.java:755)                                                          在android.view.LayoutInflater.rInflate(LayoutInflater.java:758)                                                          在android.view.LayoutInflater.inflate(LayoutInflater.java:492)                                                          在android.view.LayoutInflater.inflate(LayoutInflater.java:397)                                                          在com.example.ahr.a1000funnysms.SmsPagerAdapter.instantiateItem(SmsPagerAdapter.java:34)                                                          在android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1034)                                                          在android.support.v4.view.ViewPager.populate(ViewPager.java:1182)                                                          在android.support.v4.view.ViewPager.populate(ViewPager.java:1116)                                                          在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642)                                                          在android.view.View.measure(View.java:16552)                                                          在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:719)                                                          在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)                                                          在android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)                                                          在android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1391)                                                          在android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)                                                          在android.view.View.measure(View.java:16552)                                                          在android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                          在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)                                                          在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)                                                          在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)                                                          在android.widget.LinearLayout.measureVertical(LinearLayout.java:695)                                                          在android.widget.LinearLayout.onMeasure(LinearLayout.java:588)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:310)                                                          在com.android.internal.policy.impl.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2291)                                                          在android.view.View.measure(View.java:16552)                                                          在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1923)                                                          在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1120)                                                          在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1302)                                                          在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1007)                                                          在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5677)                                                          在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:761)                                                          在android.view.Choreographer.doCallbacks(Choreographer.java:574)                                                          在android.view.Choreographer.doFrame(Choreographer.java:544)                                                          在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:747)                                                          在android.os.Handler.handleCallback(Handler.java:733)                                                          在android.os.Handler.dispatchMessage(Handler.java:95)                                                       在android.os.Looper.loop(Looper.jav

不使用FAB,没有这样的错误

4 个答案:

答案 0 :(得分:0)

尝试使用compile 'com.android.support:design:26.+'浮动按钮,如下面的代码

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:26.+'
    compile 'com.android.support:design:26.+'


}

答案 1 :(得分:0)

FAB按钮是Design Library Cpmponent。您的活动必须扩展 AppCompatActivity 而不是活动。

答案 2 :(得分:0)

更改以下行:

android:backgroundTint="@color/pay"

这一个:

app:backgroundTint="@color/pay"

答案 3 :(得分:0)

只需添加style.xml => Theme.AppCompat.Light.DarkActionBar