android.view.InflateException:二进制XML文件行#17:错误导致类<unknown>

时间:2016-11-01 11:05:37

标签: android xml android-layout android-design-library

您好我正在尝试使用此布局启动活动,但它仅适用于Android 5+,当我在旧版本上运行它总是粉碎。可能是什么原因导致的也许我正在使用一些受限制的Android版本&lt; 5 xml字段?

样式

https://drive.google.com/open?id=0B-pbp_K-xNkEb0pQbzIzd0FYMU0 https://drive.google.com/open?id=0B-pbp_K-xNkEWlpuanl3ejhxd2c

布局

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

<style name="AppTheme.NoActionBar" >
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

样式

android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
 Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.

错误:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 24
    buildToolsVersion "23.0.2"
    enforceUniquePackageName = false

    defaultConfig {
        applicationId "com.mycrosswod.crossfit"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:24+'
    compile 'com.android.support:design:24.0.0'
    compile 'com.android.support:recyclerview-v7:24.0.0'
    compile 'com.android.support:percent:24.0.0'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.code.gson:gson:1.7.2'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp3:okhttp:3.1.2'
    compile 'com.facebook.android:facebook-android-sdk:4+'
    compile 'com.vk:androidsdk:+'
    compile 'com.google.apis:google-api-services-youtube:v3-rev163-1.21.0'
    compile 'com.thefinestartist:ytpa:1.2.1'
    compile 'com.github.clans:fab:1.6.3'
    compile "com.google.firebase:firebase-messaging:9.0.0"
    compile 'com.android.support:multidex:1.0.1'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
}

apply plugin: 'com.google.gms.google-services'

摇篮

{{1}}

3 个答案:

答案 0 :(得分:1)

关于android的问题并不知道要采取哪个主题。这是前棒棒糖和后棒棒糖设备之间的冲突,所以我们需要明确转换为无操作栏主题。添加

compile&#39; com.android.support:appcompat-v7:24.2.0&#39;

这里我的案例是v24 ,选择方便的版本。要定义棒棒糖前设备,我们在 res / values / style.xml 中更改样式方案,如下所示:< / p>

<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
</style>

<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

AppTheme继承自AppTheme.Base,它继承自Theme.AppCompat.Light.NoActionBar。所以在这里我们可以为棒棒糖前设备提供我们支持的配色方案。请注意:)

棒棒糖设备支持材料设计。我们可以在这里添加更多颜色方案。我们已经在 res / values / styles.xml 中定义了AppTheme。

现在从 res / values / values / styles.xml 继承相同的AppTheme到 res / values / values-v21 / styles.xml 。所以Values-v21 / styles.xml如下:

<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
    <item name="android:windowBackground">@color/colorAccent</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
</style>

试试这个。 : - )

答案 1 :(得分:0)

将行更改为相应的文件值/ v-2x / styles.xml

<style name="Base.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">true</item>`
    <item name="windowNoTitle">true</item>

</style>
<style name="MyTheme" parent="Base.MyTheme">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

值/ v-2x / styles.xml中的最终样式

<resources>     
<style name="CrossfitTextView" parent="@android:style/Widget.TextView">
<item name="android:textColor">@color/text_color</item>
<item name="android:drawableBottom">@color/tomato</item>
</style>
<style name="CrossfitSecondTextView" parent="@android:style/Widget.TextView">
    <item name="android:textColor">@color/text_color2</item>
</style>
<style name="CrossfitTitleTextView" parent="@android:style/Widget.TextView">
    <item name="android:textColor">@color/second_text</item>
</style>
<style name="CrossfitEditText" parent="@android:style/Widget.EditText">
    <item name="android:textSize">16sp</item>
    <item name="android:maxLines">1</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/text_color</item>
</style>
<style name="Crossfit.Button" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/colorPrimary</item>
    <item name="colorControlHighlight">@color/colorPrimary</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:gravity">center</item>
</style>
<style name="Crossfit.F" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/com_facebook_button_background_color</item>
    <item name="colorControlHighlight">@color/com_facebook_button_background_color</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:gravity">center</item>
    <item name="android:drawableLeft">@drawable/com_facebook_button_icon</item>
</style>
<style name="Crossfit.V" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/vk_share_blue_color</item>
    <item name="colorControlHighlight">@color/vk_share_blue_color</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:gravity">center</item>
    <item name="android:drawableLeft">@drawable/com_facebook_button_icon</item>
</style>
<style name="CustomActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <!-- Support library compatibility -->
    <item name="windowActionBarOverlay">true</item>
</style>


<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/colorPrimary</item>
<item name="android:windowBackground">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
</style>

<style name="MyTheme.Detail" parent="MyTheme">
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="cfButton" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/colorPrimary</item>
    <item name="android:colorButtonNormal">@color/colorPrimary</item>
    <item name="colorControlHighlight">@color/colorPrimaryDark</item>
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="MenuButtonsSmall">
    <item name="fab_size">mini</item>
    <item name="fab_colorNormal">@color/end</item>
    <item name="fab_colorPressed">@color/end</item>
    <item name="fab_colorRipple">@color/end</item>
</style>
<style name="mytext" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/text_color</item>
    <item name="android:textColorHint">@color/text_color</item>
    <item name="colorAccent">@color/text_color</item>
</style>
</resources>

在values / styles.xml中进行的更改

<style name="AppThemeSignIn" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/background</item>
    <item name="colorPrimaryDark">@color/background</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

values / styles.xml中的最终样式

<resources>     
<style name="CrossfitTextView" parent="@android:style/Widget.TextView">
    <item name="android:textColor">@color/text_color</item>
</style>

<style name="CrossfitEditText" parent="@android:style/Widget.EditText">
    <item name="android:textColor">@color/text_color</item>
    <item name="android:textColorHint">@color/text_color</item>
</style>

<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
</style>

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


 <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

 <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
 <style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item    name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>

 <style name="MaterialDialogSheetAnimation">
    <item name="android:windowEnterAnimation">@anim/popup_show</item>
    <item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

 <style name="MenuButtonsSmall">
    <item name="fab_size">mini</item>
    <item name="fab_colorNormal">#026158</item>
    <item name="fab_colorPressed">#026158</item>
    <item name="fab_colorRipple">#026158</item>
</style>

 <style name="MenuButtonNormal">
    <item name="fab_size">normal</item>
    <item name="fab_colorNormal">#026158</item>
    <item name="fab_colorPressed">#026158</item>
    <item name="fab_colorRipple">#026158</item>
</style>
</resources>

答案 2 :(得分:0)

您使用的是矢量图片吗?

如果您尝试将所有android:src替换为app:srcCompat(当您指的是矢量图片时)