浮动操作button和devise库膨胀错误

我正在使用devise支持库

defaultConfig { vectorDrawables.useSupportLibrary = true ... } dependencies { compile 'com.android.support:design:23.4.0' compile 'com.android.support:support-v4:23.4.0' ... } 

当我添加FloatingActionButton

 <android.support.design.widget.FloatingActionButton android:layout_gravity="right" android:layout_margin="20dp" android:tint="#fff" android:src="@drawable/ic_menu_manage" app:backgroundTint="#b3000000" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

到我的布局之一,我得到这个错误

 Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. 

这是我的主要活动( it has navigation drawer

 public class MapNavActivity extends AppCompatActivity 

我知道它应该工作,如果我将AppCompatActivity更改为Activity

然而,这不适合我。 这是清单文件中定义的活动

 <activity android:name=".MapNavActivity" android:label="@string/title_activity_map_nav" android:theme="@style/AppTheme.NoActionBarMain" /> 

这是styles.xml文件中的主题

 <style name="AppTheme.NoActionBarMain" parent="Theme.AppCompat.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> 

我陷入了这个问题差不多5个小时。 有谁知道如何解决这个问题?

编辑清单文件

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rojus.zvyjybos.com.zvejybosrojus2"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-feature android:name="android.hardware.sensor.accelerometer" /> <uses-feature android:name="android.hardware.sensor.compass" /> <application android:name=".start.App" android:allowBackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".start.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MapNavActivity" android:label="@string/title_activity_map_nav" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.LakeDetailActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.FishActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.BitesActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.FishingMethodsActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".fragments.MyFishingPlanDetailList" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".menu_activities.DetailPlaceActivity" android:theme="@style/AppTheme.NoActionBarMain" /> <activity android:name=".augumented_reality.AugumentedActivity" /> <activity android:name=".start.MainMenu" android:theme="@style/AppTheme.NoActionBarMain" /> </application> </manifest> 

我也将增加完整的例外

 Process: rojus.zvyjybos.com.zvejybosrojus2, PID: 26070 java.lang.RuntimeException: Unable to start activity ComponentInfo{rojus.zvyjybos.com.zvejybosrojus2/rojus.zvyjybos.com.zvejybosrojus2.MapNavActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.FloatingActionButton at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) 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:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.FloatingActionButton at android.view.LayoutInflater.createView(LayoutInflater.java:633) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) 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:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) 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:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34) at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:116) at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:110) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916) at android.view.LayoutInflater.rInflate(LayoutInflater.java:802) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.customMapView(MapFragment.java:416) at rojus.zvyjybos.com.zvejybosrojus2.map.MapFragment.onViewCreated(MapFragment.java:322) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6068) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2342) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5431) 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:914) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 

我只是在一个新的项目中试过你的代码,它在我的机器上工作正常。 确保compile 'com.android.support:appcompat-v7:23.4.0'在你的build.gradle文件中,然后做一个重build,看看是否有帮助。 同时检查你的SDKpipe理器,看看你有没有安装任何旧的更新。

好吧,去简单的方法。

首先添加依赖到你的build.gradle。

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' 

}

然后打开你的XML文件并添加浮动动作button。

 <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /> 

然后打开你的.java文件并初始化浮动button

 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Click action // write you code here. } }); 

然后清理你的项目并运行它。

我希望这个解决scheme帮助你。