本文介绍了错误夸大类Android支持设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是使用这里提到的新的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支持设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 23:48
查看更多