java.lang.RuntimeException:android.view.InflateException
这是我的XML文件,我不知道我收到了一个错误 我试图在线性布局中创建嵌套布局。有人能帮我解释为什么会出现这个错误吗?我还附上了我的xml文件来查看它。 如果我对第一个文本视图进行注释,则错误显示在下一个文本视图上 我已经参考了他的意见,但我无法解决这个问题java.lang.RuntimeException:android.view.InflateException,android,android-layout,Android,Android Layout,这是我的XML文件,我不知道我收到了一个错误 我试图在线性布局中创建嵌套布局。有人能帮我解释为什么会出现这个错误吗?我还附上了我的xml文件来查看它。 如果我对第一个文本视图进行注释,则错误显示在下一个文本视图上 我已经参考了他的意见,但我无法解决这个问题 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@style/TextAppearance.AppCompat.Display3"
android:background="@color/back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:paddingBottom="2dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/top"
android:textColor="#ffffff"
android:textSize="20sp"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="571dp"
android:layout_margin="20dp"
android:background="@drawable/ticket1"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="189dp"
android:layout_height="121dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:src="@drawable/right" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:text="@string/pnr_no"
android:textColor="@color/back"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="40dp"
android:text="@string/name"
android:textColor="#000000"
android:textSize="40sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phn"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date"
android:textColor="#000000"
android:textSize="15sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="37dp"
android:layout_marginLeft="37dp"
android:layout_marginTop="17dp"
android:text="Home"
android:textColor="@color/back"
android:textSize="20dp"
android:padding="10dp"
android:background="@drawable/my_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
android:layout_marginTop="17dp"
android:text="Book another \n ticket"
android:textColor="@color/back"
android:textSize="12dp"
android:padding="10dp"
android:background="@drawable/my_button"
/>
</RelativeLayout>
</LinearLayout>
导致InflateException错误的原因是代码中的第5行
android:theme=“@style/TextAppearance.AppCompat.Display3”
因此,删除它,代码就会正常运行。我想这就是你一直在寻找的答案
现在,如果您想为当前布局中的所有文本视图设置自定义外观,您应该在SO帖子中查看
你可以用像
<style name="QTheme" parent="android:Theme.Light">
<item name="android:textViewStyle">@style/TextAppearance.AppCompat.Display3</item>
</style>
@style/TextAppearance.AppCompat.Display3
注意父主题。
让我们知道,如果这有助于解决您的问题添加java类代码,则TextView类中存在错误。
<style name="QTheme" parent="android:Theme.Light">
<item name="android:textViewStyle">@style/TextAppearance.AppCompat.Display3</item>
</style>