C# Android.Views.InflateException:使用自定义按钮选择器对类Android.widget.Button进行充气时出错
我在另一个项目中遇到了一些问题,所以我创建了一个新的项目,看看我是否也遇到了同样的错误 我在main.axml中创建了一个按钮,我正在尝试使用somestyle.xml对其进行样式设置 somestyle.xml:C# Android.Views.InflateException:使用自定义按钮选择器对类Android.widget.Button进行充气时出错,c#,android,xamarin,C#,Android,Xamarin,我在另一个项目中遇到了一些问题,所以我创建了一个新的项目,看看我是否也遇到了同样的错误 我在main.axml中创建了一个按钮,我正在尝试使用somestyle.xml对其进行样式设置 somestyle.xml: <?xml version="1.0" encoding="utf-8" ?> <selector xmlns:android="http://schemas.android.com/apk/res/androi
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- What to do when the button is NOT pressed -->
<item android:state_pressed="false">
<layer-list>
<item android:right="5dp" android:top="5dp">
<!-- Shape the button -->
<corners android:radius="20dp"/>
<solid android:color="#d13838"/>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270" android:endColor="#d13838" android:startColor="#d13838"/>
<stroke android:width="1dp" android:color="#d13838"/>
<corners android:radius="4dp"/>
<padding android:bottom="0dp" android:left="10dp" android:right="10dp" android="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn"
android:text="Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/somestyle" />
</LinearLayout>
using Android.App;
using Android.Widget;
using Android.OS;
namespace TestNamespaceBug
{
[Activity(Label = "TestNamespaceBug", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
}
Main.axml:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- What to do when the button is NOT pressed -->
<item android:state_pressed="false">
<layer-list>
<item android:right="5dp" android:top="5dp">
<!-- Shape the button -->
<corners android:radius="20dp"/>
<solid android:color="#d13838"/>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270" android:endColor="#d13838" android:startColor="#d13838"/>
<stroke android:width="1dp" android:color="#d13838"/>
<corners android:radius="4dp"/>
<padding android:bottom="0dp" android:left="10dp" android:right="10dp" android="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn"
android:text="Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/somestyle" />
</LinearLayout>
using Android.App;
using Android.Widget;
using Android.OS;
namespace TestNamespaceBug
{
[Activity(Label = "TestNamespaceBug", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
}
我不知道是什么导致了所有的警告和异常。非常感谢您对如何解决此问题提出的任何建议。我确实认为您的“塑造按钮”项目遗漏了一个
无法相信它是如此愚蠢的事情,谢谢!你知道这些警告是怎么回事吗?我从来没有用过Xamarin,所以不,我没有:)