In Android 3.0, the concept of "checked" can be rendered using an "activated" background. This gives you the persistent bar you see when you tap on a list fragment, providing context for the fragment to the list's right (e.g., tapping on a folder in Gmail highlights that folder and opens up another list fragment to show the conversations in that folder).
For example, the fragment samples show stuff like:
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));
That resource (android.R.layout.simple_list_item_activated_1
) is new to Android 3.0. What makes it "activated" is:
android:background="?android:attr/activatedBackgroundIndicator"
That attribute value is new to Android 3.0 and will cause you to crash if you try using it on earlier versions of Android, from what I can tell. I want to set the background to this magic value for the 3.0/large/landscape combination, and skip it otherwise.
I can accomplish this by having two separate versions of the layout, one in a -v11
resource set, one in a regular resource set. This is a bit less DRY than I'd like, though, since the bulk of the layout is the same, with only this one attribute either being included or being skipped.
I took a stab at trying to use drawable resource aliases, so the android:background
could refer to the alias and the alias would handle the -v11
differentiation, but <bitmap>
drawables don't seem to like android:src="@null"
.
I suspect there's a styles-and-themes approach to this problem, but since I've never fully wrapped my head around those (one of my more embarrassing Android knowledge gaps), I'm not completely sure what to do.
Has anyone worked out a pattern for using "activated" on 3.0 and skipping it on pre-3.0, beyond separate layouts?
Thanks!
<include>
wouldn't help here -- I need the background on the root element of the row layout. "different versions of a theme" is certainly in the realm of possibility, but that's why I'm asking the question. :-) – Darksome@android:color/transparent
? – Lounge@null
? That might work. Off the cuff, I would think the styles approach Al outlines would be more "proper", in terms of fidelity with the Android vision -- do you agree? At the end of the day, after all, this question is less about me and more about what I tell my readers, so I want to go the route that Google would like Android developers to use. – Darksome@null
problem :-) – Lounge