I have a View that I set a selector background to that should reacht to touches. It does, but only on 4.x. On 2.3 it just doesn't react to touches. What could be the problem? Here's the layout:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/idee_baden"
android:scaleType="centerInside" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/background_selector" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:ellipsize="end"
android:padding="4dp"
android:singleLine="true"
android:textAppearance="@style/SmallTextBold"
android:textColor="#ffffff" />
</RelativeLayout>
And this is the background_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue9"
android:state_pressed="true" />
<item android:drawable="@drawable/black9" />
</selector>
This functionality has been enabled since API 1 - so I don't think this has anything to do with the OS level being supported, but more to do with your selector code being poorly formatted.
I think your selector is not properly formatted. I think your 'item' tag sections should be filled out more completely, and you should have more of them.
Here is one of the selectors I use (more complete, but still missing some of the options regarding focus vs. pressed). Keep in mind that order matters (this is evaluated from top to bottom):
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/circle_button_on"
android:state_focused="true"
android:state_pressed="true"/>
<item
android:drawable="@drawable/circle_button_on"
android:state_focused="false"
android:state_pressed="true"/>
<item
android:drawable="@drawable/circle_button_off"
android:state_focused="true"
android:state_pressed="false"/>
<item
android:drawable="@drawable/circle_button_off"
android:state_focused="false"
android:state_pressed="false"/>
</selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With