ListView With Nine-Patch Item Background Issues

血红的双手。 提交于 2019-12-01 23:38:23

I was gonna delete this thread, but I can't so I'll see if I can't use this as an example of what not to do :)

First, in the ListView XML: android:listSelector="@drawable/shop_list_selector"
Don't do that!

What I was trying to do here was set the background of the list items and the android:background property didn't work. You may have noticed that the item XML is missing, and that is because it was missing from my head! (I never touched it over the countless hours I was hammering away at this 'issue') So the line android:background="@drawable/shop_list_selector" goes in the item's properties and everything is groovy. (Remember the XML above is very wrong so don't use it!)

...Well except that it doesn't look as good in real life as it did in my head :(
Back to the drawing board!!!

You havent defined a "normal" state, see this example

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/blue"
          android:state_pressed="true" />
    <item android:color="@color/red"
          android:state_selected="true" />
    <item android:color="@color/white" />
</selector>

in here white is the "normal" state, in here you can find some documentation about it.

I hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!