Hi,

I have a linear layout that is focusable, I'd like it to use the same
background drawable as found in listview items:

    StateListDrawable sld =
(StateListDrawable)context.getResources().getDrawable(
        android.R.drawable.list_selector_background);
    linearLayout..setBackgroundDrawable(sld);
    linearLayout.setFocusable(true);

The default state of this selector is to be transparent, but I want a
specific background drawable used in an unselected state. It would be
ideal if we could just "override" this one state, and leave everything
else the same:

    sld.addState(new int[] { -android.R.attr.state_window_focused },
        context.getResources().getDrawable(R.drawable.my_background));

That seems to work - but if I display a menu in the parent activity,
the background reverts to transparent again. When the menu is hidden,
the background comes back to the drawable I had used for the override.
I'm not sure what states I could override to fix the menu-display-
state-issue - but I'm not sure if this is even a proper use of
StateListDrawables. I could just make my own sld to mimic what the one
bundled with android does, but if I make its highlight state orange
for example, it'll look strange on some devices that have changed the
focus color to green for example with listviews (droid eris for
example). It'd be great to keep everything consistent.

Below is the xml def for android.R.drawable.list_selector_background.
If anyone knows what states to change for the menu display, that'd be
great.

Thanks




   <selector xmlns:android="http://schemas.android.com/apk/res/
android">

       <item android:state_window_focused="false"
           android:drawable="@color/transparent" />

       <!-- Even though these two point to the same resource, have two
states so the drawable will invalidate itself when coming out of
pressed state. -->
       <item android:state_focused="true"
android:state_enabled="false"
           android:state_pressed="true"
           android:drawable="@drawable/
list_selector_background_disabled" />
       <item android:state_focused="true"
android:state_enabled="false"
           android:drawable="@drawable/
list_selector_background_disabled" />

       <item android:state_focused="true" android:state_pressed="true"
           android:drawable="@drawable/
list_selector_background_transition" />
       <item android:state_focused="false"
android:state_pressed="true"
           android:drawable="@drawable/
list_selector_background_transition" />

       <item android:state_focused="true"
           android:drawable="@drawable/
list_selector_background_focus" />

   </selector>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to