我跟着这个YouTube Tutorial 一些我的自定义按钮是如何透明的,这是我的自定义按钮的xml代码,我可以构建,但应用程序立即崩溃。
exeprion是 Android.Views.InflateException:二进制XML文件行#1:错误膨胀类android.widget.Button<selctor xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item android:right="5dp" android:top="5dp">
<corners android:radius = "2dp"/>
<solid android:color ="#BABABA"/>
</item>
<item android:bottom="2dp" android:left ="2dp">
<shape>
<gradient android:angle="270" android:endColor = "#4A6EA9" android:startColor ="#4A6EA9"/>
<stroke android:width="1dp" android:color ="#D6D6D6"/>
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp" />
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<layer-list>
<item android:right="5dp" android:top="5dp">
<corners android:radius = "3dp"/>
<solid android:color ="#4A6EA9"/>
</item>
<item android:bottom="2dp" android:left ="2dp">
<shape>
<gradient android:angle="270" android:endColor = "#4A6EA9" android:startColor ="#4A6EA9"/>
<stroke android:width ="1dp" android:color ="#BABABA"/>
<corners android:radius="5dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selctor>
答案 0 :(得分:0)
缺少形状标记:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius = "2dp"/>
<solid android:color ="#BABABA"/>
</shape>
</item>
<item android:bottom="2dp" android:left ="2dp">
<shape>
<gradient android:angle="270" android:endColor = "#4A6EA9" android:startColor ="#4A6EA9"/>
<stroke android:width="1dp" android:color ="#D6D6D6"/>
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp" />
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius = "3dp"/>
<solid android:color ="#4A6EA9"/>
</shape>
</item>
<item android:bottom="2dp" android:left ="2dp">
<shape>
<gradient android:angle="270" android:endColor = "#4A6EA9" android:startColor ="#4A6EA9"/>
<stroke android:width ="1dp" android:color ="#BABABA"/>
<corners android:radius="5dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>