ListView With Nine-Patch Item Background Issues

前端 未结 2 392
误落风尘
误落风尘 2021-01-21 13:29

WARNING: The XML in this question is wrong, read the answer before you confuse yourself!


I have been banging my head on the wall for a while now.

相关标签:
2条回答
  • 2021-01-21 13:43

    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

    0 讨论(0)
  • 2021-01-21 13:46

    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!!!

    0 讨论(0)
提交回复
热议问题