android.view.InflateException:二进制XML文件第48行:错误膨胀了类TextView

时间:2018-09-20 05:32:17

标签: android colors android-theme layout-inflater typed-arrays

我检查了很多主题,但没有收到答案。 代码停留在setContentView(R.layout.activity_entrance); 例外

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gootax.driver/com.gootax.driver.EntranceActivity}: android.view.InflateException: Binary XML file line #48: Binary XML file line #48: Error inflating class TextView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
    at android.app.ActivityThread.access$900(ActivityThread.java:154)
......
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x5ef "res/color/secondary_text_material_dark.xml" a=1 r=0x1060166}
    at android.content.res.TypedArray.getColor(TypedArray.java:447)
    at android.widget.TextView.<init>(TextView.java:745)
    at android.widget.TextView.<init>(TextView.java:678)

好的,我检查布局及其48行。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFE6E6E6"
    android:orientation="vertical">
    <!--android:background="?attr/bg_main"-->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="3">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_marginTop="20dp"
            android:background="@android:color/transparent"
            android:src="@drawable/pic"
            tools:ignore="ContentDescription" />
    </FrameLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">


        <FrameLayout
            android:id="@+id/framelayout_servicelist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <LinearLayout
                android:id="@+id/linearlayout_list_service"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="30dp"
                android:background="#FFFFFFFF"
                android:orientation="vertical"
                android:paddingBottom="30dp">
                <!--android:background="?attr/bg_second"-->

                <TextView   <-- This line 48
                    android:id="@+id/textview_entrance_info"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="30dp"
                    android:layout_marginLeft="50dp"
                    android:layout_marginRight="50dp"
                    android:layout_marginTop="30dp"
                    android:gravity="center_horizontal"
                    android:textColor="@color/grey_text"
                    android:text="@string/text_entrancefragment_entrance" />
                <ListView
     .....

我有自定义主题

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="bg_main">@color/bg_main_light</item>
    <item name="bg_second">@color/bg_second_light</item>
    <item name="bg_second_comment">@color/bg_second_comment_light</item>
    <item name="text_main">@color/text_main_light</item>
    <item name="text_subscribe">@color/text_subscribe_light</item>
    <item name="android:textSize">@dimen/textsize_textviews</item>
    <item name="android:textColorSecondaryInverse">@color/text_main_dark</item>
</style>

什么是问题?我的主题是覆盖默认主题,并且不能缺少xml。我没有此资源:“ res / color / secondary_text_material_dark.xml”,但我不需要它。请帮我

1 个答案:

答案 0 :(得分:0)

@UmangBurman,谢谢您的帮助。

我的错误是与AppPreferences有关。在启动应用程序时,请阅读安装主题并进行设置。我认为这是不正确的。

if (appPreferences.getText("theme").length() > 0) {
            setTheme(Integer.valueOf(appPreferences.getText("theme")));
        } else {
            setTheme(AppParams.THEME_DEFAULT);
            appPreferences.saveText("theme", String.valueOf(AppParams.THEME_DEFAULT));
        }
    setTheme(AppParams.THEME_DEFAULT);