android - android.view.InflateException: Binary XML file line #48: Error inflating class TextView
问题描述
我检查了很多主题,但没有收到答案。代码卡在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”,但我不需要它。请帮我
解决方案
谢谢你的帮助,@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);
推荐阅读
- publish-subscribe - 如何在 dolphindb 中订阅流表
- r - 将纽约州法院数据中的数据转换为要可视化的数据框 R(导入但未成为正确的数据框)
- git - git-svn 死于信号 11
- java - 如何使用 kotlin 或 java 将倒数计时器设置为一天中的特定时间?
- python - 如何在 tkinter 中的屏幕/帧之间切换?
- jupyter-notebook - 无法在 OSX 10.11 中使用 xeus-cling 内核
- android - 如何在 Android Studio 中添加 gradle 的任务参数?
- sql - Only SubQuery expressions that are top level conjuncts are allowed error
- go - HTTP GET,来自特定本地 IP,使用备用 DNS
- sql - “缺少右括号”