android.view.InflateException:二进制XML文件行#18:二进制XML文件行#18:膨胀类按钮时出错
膨胀类按钮时出错 代码如下: 主要活动android.view.InflateException:二进制XML文件行#18:二进制XML文件行#18:膨胀类按钮时出错,android,Android,膨胀类按钮时出错 代码如下: 主要活动 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/too
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="@color/colorPrimaryDark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginTop="100dp">
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:padding="15dp"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:text="Donor"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="16dp"
android:id="@+id/donor"
/>
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:padding="15dp"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:layout_marginBottom="20dp"
android:text="Recipient"
android:textStyle="bold"
android:textColor="#ffffff"
android:textSize="16dp"
android:id="@+id/recipient"
/>
</LinearLayout>
</RelativeLayout>
边界:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners android:radius="30dp"/>
<stroke android:color="#ffffff" android:width="1dp"/>
</shape>
</item>
<item android:state_pressed="true">
<shape>
<solid android:color="@color/colorPrimaryDark"/>
</shape>
</item>
</selector>
请帮我修一下。MainActivity的setContentView中显示错误。
这个错误在项目的每个活动中都会出现。我刚刚尝试先启动另一个活动,但它显示了完全相同的错误,即setContentView中的错误。在
res/drawable
文件夹中查找边框\u white.xml
,并检查末尾是否有类似的内容:(v24)
如果是这种情况,请复制此文件并将其粘贴到
res/drawable
notres/drawable-v24
中
节点在drawable/border\u-white.xml
中缺少所需的属性android:layou-height
和android:layou-width
,这使其无效。添加缺少的属性,它会膨胀。它们很可能都是match\u parent
(或wrap\u content
)
我不明白为什么在RelativeLayout中使用LinearLayout,而在RelativeLayout中使用orientation:vertical。您必须使用SP进行文本测量,并且您正在使用DP。您还必须在res文件夹中使用@String,并使用@Color和@dimen。 xmlns:app=”http://schemas.android.com/apk/res-auto“图书馆从未被使用过。 你确定你的字体有粗体风格吗?为什么要使用android:state_pressed=“true”?当您按下按钮时,自动启动新活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity"
android:background="@color/colorPrimaryDark">
<Button
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:padding="@dimen/button_padding"
android:text="@string/donor"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="16sp"
android:id="@+id/donor"
/>
<Button
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:padding="@dimen/button_padding"
android:layout_marginBottom="@dimen/button_margin"
android:text="@string/recipient"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="16sp"
android:id="@+id/recipient"
/>
</LinearLayout>
a提示:删除所有属性,除了android:layout\u width
和android:layout\u height
之外,并尝试逐个添加它们,以检查您的错误和@drawable/border\u white
在哪里?@AnkitKataria查看我编辑的答案
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity"
android:background="@color/colorPrimaryDark">
<Button
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:padding="@dimen/button_padding"
android:text="@string/donor"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="16sp"
android:id="@+id/donor"
/>
<Button
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:padding="@dimen/button_padding"
android:layout_marginBottom="@dimen/button_margin"
android:text="@string/recipient"
android:fontFamily="@font/nunito_semibold"
android:background="@drawable/border_white"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="16sp"
android:id="@+id/recipient"
/>
</LinearLayout>