1

While I'm touching something in a ListView I get a blue highlight. Now I have another view elsewhere that I want to look the same; I tap on it and get a blue highlight. I thought this was a list_selector_background, but when I try that I get an orangey color.

My first question is: what is the style for the stock ListView item's background when selected?

Second (and more importantly), how do I figure this out? I'm looking for the chain of investigation, like...

  • List item
  • Look at the default theme (ABC)
  • Look at theme ABC for the style (QWE)
  • Look at style QWE and get the selected drawable (RTY)
  • Look at drawable RTY

Or whatever the actual investigation trail is

Hounshell
  • 5,321
  • 4
  • 34
  • 51
  • I've a feeling this could be interesting to check: http://stackoverflow.com/questions/2562051/listview-item-background-via-custom-selector – Vit Khudenko Jun 21 '12 at 19:22
  • I did see that, and it does illustrate how to set it per-item, but I'm looking for something a little deeper than that. My goal is to make my app look perfectly stock. Colors and styles should be consistent with stock OS colors and styles. I'm fine with doing layout and drawables per OS version to achieve that, but my trouble is really figuring out what those styles are without using a graphics editor to check each color at various points on a screenshot. I want to learn how to figure out what these are in stock from the source. – Hounshell Jun 21 '12 at 20:47
  • well, if I'm not missing anything and your goal is a list that looks native to OS/device, then you should just be able to get it without any additional efforts, just don't override any colors/backgrounds for `ListView` and make sure list item does not use any custom background either. – Vit Khudenko Jun 22 '12 at 06:45

1 Answers1

0

In your layout .xml for this view you want to add a new .xml called button_selector to the attributue android:background like so...

android:background="@drawable/button_selector"

Then create a new android .xml in the drawable folder called button_selector.xml containing this code....

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected -->
    <item android:drawable="@drawable/button_selected"
          android:state_focused="true" />
    <!-- When not selected-->
    <item android:drawable="@drawable/button_unselected" />
</selector>

Then create your button_unselected.xml and button_selected.xml in the drawable folder as well for the layout of each of the buttons.

this is an example of one of my button_unselected.xml files ....

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle" >
        <solid android:color="#10000000" />

        <padding
            android:bottom="4dp"
            android:top="4dp" />

        <corners android:radius="5dp" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >


        <solid android:color="#20558e34" />
    </shape>
</item>
</layer-list>

Hope this helps...

CommonKnowledge
  • 769
  • 1
  • 10
  • 35