错误膨胀类 Android 支持设计 [英] Error inflating class Android support design
问题描述
我想要做的是使用这里提到的新的 android 支持设计库:http://android-developers.blogspot.com/2015/05/android-design-support-library.html.
What I am trying to do is use the new android support design library mentioned here: http://android-developers.blogspot.com/2015/05/android-design-support-library.html.
我尝试在我的 xml 布局中使用如下浮动操作按钮(这是以下错误的来源):
I have attempted to use the floating action button as follows in my xml layout (this is where the below error is coming from):
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/adview"
android:layout_marginTop="500dp" />
当我的应用程序启动时,这是错误:
When my app is launched this is the error:
06-06 20:56:43.186 6405-6405/com.nick.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.nick.app, PID: 6405
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nick.app/com.nick.app.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5290)
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:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: android.view.InflateException: Binary XML file line #7: 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.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:401)
at android.app.Activity.setContentView(Activity.java:2197)
at com.nick.app.MainActivity.onCreate(MainActivity.java:94)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5290)
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:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
在应用程序模块的 build.gradle
文件中,我根据需要 compile 'com.android.support:design:22.2.0'
.此外,其他相关build.gradle
文件中的部分:
in my build.gradle
file for the app module I have compile 'com.android.support:design:22.2.0'
as required.Also, other relevant parts from the build.gradle
file:
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 21
.....
我还应该注意,当我转到项目结构->依赖项并尝试添加库依赖项时,我在搜索时找不到com.android.support:design:22.2.0"(我不确定这是否除了在 build.gradle 文件中添加依赖项外,还需要).
I should also note that when I go to project structure->dependencies and I try to add a library dependency I cannot find "com.android.support:design:22.2.0" when searching (I am not sure if this is required in addition to adding the dependency in build.gradle file).
最后,在我的 SDK 管理器中,我确认Android 支持库"和Android 支持库"分别是最新的 15 和 22.2 版本.
Finally, in my SDK manager I have confirmed "Android Support Repository" and "Android Support Library" are up to date at versions 15 and 22.2, respectively.
对于我可以尝试的其他方法有什么建议吗?
Are there any suggestions for what else I might try?
我找到了这个答案:https://stackoverflow.com/a/30557995/1489990并尝试了解决方案但是它并没有解决我的问题.
I have found this answer: https://stackoverflow.com/a/30557995/1489990 and tried the solution however it did not solve my issue.
推荐答案
如果您正在使用任何设计库组件,您应该确保您的活动扩展 AppCompatActivity 并使用适当的 Theme.AppCompat
主题.请注意,FloatingActionButton
依赖于在您的主题上设置的 colorAccent
- 确保您的主题已定义.
If you are using any of the Design Library components, you should ensure your activity extends AppCompatActivity and uses an appropriate Theme.AppCompat
theme. Note that the FloatingActionButton
relies on the colorAccent
set on your theme - ensure your theme has that defined.
这篇关于错误膨胀类 Android 支持设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!