xml背景设置为圆角,圆角不显示问题
你在xml中设置背景为圆角背景,但运行后发现圆角没有显示出来,这是为什么呢?这时候你要考虑到item的背景是不是圆角的,如果item的背景不是圆角的,那么肯定显示不出来圆角,因为背景的圆角效果被item的非圆角效果覆盖掉了。
设置view的selected无效:
比如布局文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="@color/ffffffff"/>
</shape>
</item>
<item android:state_selected="true" >
<shape android:shape="rectangle">
<solid android:color="@color/cccccc"/>
</shape>
</item>
</selector>
这时候view设置selected,但选中区域的颜色并没有发生变化,修改xml,将android:state_selected=“true” item移到不选中item的前面就可以解决此问题
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" >
<shape android:shape="rectangle">
<solid android:color="@color/cccccc"/>
</shape>
</item>
<item >
<shape android:shape="rectangle">
<solid android:color="@color/ffffffff"/>
</shape>
</item>
</selector>
本文探讨了在XML中设置圆角背景时遇到的问题,以及如何正确配置View的状态属性,如selected,以实现预期的视觉效果。通过调整XML布局文件中item的顺序,可以确保圆角和颜色变化正确显示。

3354

被折叠的 条评论
为什么被折叠?



