gpt4 book ai didi

安卓.view.InflateException : Binary XML file line #17: Error inflating class

转载 作者:行者123 更新时间:2023-11-30 00:54:47 24 4
gpt4 key购买 nike

您好,我正在尝试使用此布局启动 Activity,但它仅适用于 Android 5+,当我在旧版本上运行它时,它总是会崩溃。这可能是什么原因造成的?也许我正在使用一些受限制的 android 版本 <5 xml 字段?

样式

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

布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sport"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical">

<LinearLayout
android:id="@+id/title_lay"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="@color/background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp">

<FrameLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="16dp">

<ImageView
android:id="@+id/iv_icon"
android:layout_width="40dp"
android:layout_height="40dp" />

</FrameLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/club_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="16sp"
android:textColor="@color/second_text" />

<TextView
android:id="@+id/club_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/text_color" />
</LinearLayout>


</LinearLayout>

<LinearLayout
android:id="@+id/subscription_lay"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/title_lay"
android:layout_marginBottom="8dp"
android:background="@drawable/backgroundtoolbar"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
android:layout_width="24dp"
android:layout_height="24dp" />

<TextView
android:id="@+id/subscription_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_subscribe_on"
android:textSize="16sp" />

</LinearLayout>

<android.support.v7.widget.CardView
android:id="@+id/address_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/second_background"
android:layout_below="@id/subscription_lay"
app:cardCornerRadius="4dp"
>

<RelativeLayout
android:id="@+id/address_lay"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/second_background"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<TextView
android:id="@+id/club_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/second_text" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_maps_place" />
</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/schedule_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/second_background"
android:layout_below="@id/address_card_view"
app:cardCornerRadius="4dp"
>

<RelativeLayout
android:id="@+id/schedule_lay"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@color/second_background"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/club_schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/schedule_title"
android:gravity="center_vertical"
android:textColor="@color/text_color" />

<TextView
android:id="@+id/schedule_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:gravity="center_vertical"
android:textColor="@color/second_text" />
</LinearLayout>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_notification_event_note" />
</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/contact_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/second_background"
android:layout_below="@id/schedule_card_view"
app:cardCornerRadius="4dp"
>

<RelativeLayout
android:id="@+id/contact_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/second_background"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<RelativeLayout
android:id="@+id/phone_lay"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="64dp">

<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/phone_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:gravity="center_vertical"
android:textColor="@color/text_color" />

<TextView
android:id="@+id/phone_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:gravity="center_vertical"
android:textColor="@color/second_text" />
</LinearLayout>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_maps_local_phone" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/web_lay"
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center_vertical"
android:layout_below="@id/phone_lay">

<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/web_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:textColor="@color/text_color" />

<TextView
android:id="@+id/web_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:textColor="@color/second_text" />
</LinearLayout>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_language" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/mail_lay"
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center_vertical"
android:background="@color/second_background"
android:layout_below="@id/web_lay">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:id="@+id/mail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:gravity="center_vertical"
android:textColor="@color/text_color" />

<TextView
android:id="@+id/mail_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12-3123-123-34"
android:gravity="center_vertical"
android:textColor="@color/second_text" />
</LinearLayout>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_content_send" />
</RelativeLayout>

<View
android:id="@+id/devider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/mail_lay"
android:paddingLeft="-30dp"
android:paddingRight="-30dp"
android:background="@color/second_background" />

<RelativeLayout
android:id="@+id/other_lay"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:layout_below="@id/devider">

<TextView
android:id="@+id/club_contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/detail"
android:layout_centerVertical="true"
android:textColor="@color/text_color" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_hardware_keyboard_arrow_right" />
</RelativeLayout>

</RelativeLayout>

</android.support.v7.widget.CardView>
</RelativeLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

样式

 <!-- 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'

最佳答案

关于android的问题,不知道该选哪个主题。这是前 Lollipop 和后 Lollipop 设备之间的冲突,因此我们需要明确转换为无操作栏主题。添加

编译'com.android.support:appcompat-v7:24.2.0'

这里我的案例是 v24,选择您方便的版本。为了定义 Lollipop 之前的设备,我们更改了 res/values/style.xml 中的样式方案,如下所示:

<!-- 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。所以在这里我们可以在这里提及我们支持的 Lollipop 前设备的配色方案。就是这样:)

Lollipop 设备支持的 Material 设计。我们可以在这里添加更多的配色方案。我们已经在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>

试试这个。 :-)

关于安卓.view.InflateException : Binary XML file line #17: Error inflating class <unknown>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40358817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com