I have a FrameLayout which i want to apply foreground drawable for it via selector , i am trying to implement "drawSelectorOnTop" but for a simple layout
now the selector does not apply when the user press "state_pressed"
here is my code :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/cell_background_selector" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#282828"
android:paddingBottom="5dp" >
..
......
........
</RelativeLayout>
</FrameLayout>
here is my selector code :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/video_blank" android:state_pressed="true"/>
<item android:drawable="@drawable/fav_show"/>
</selector>
both images exist , but the FrameLayout always apply the normal state drawable as a Foreground
The documentation states the android:foreground defines the drawable to draw over the content , it doesn't state anywhere that the content has to be a ViewGroup . And the tag is defined for the View class.
Frame Layout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.
3. android:foregroundGravity. Defines the gravity to apply to the foreground drawable. The gravity defaults to fill. Possible values are top, bottom, left, right, center, center_vertical, center_horizontal etc.
Android Framelayout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen. Generally, we can say FrameLayout simply blocks a particular area on the screen to display a single view.
Old question, but was the first hit on Google when I encountered a similar problem.
Do you have an OnClick listener set for the FrameLayout? If not, the pressed state will never be used.
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