Home » Java » FrameLayout foreground with selectors

FrameLayout foreground with selectors

Posted by: admin December 28, 2021 Leave a comment

Questions:

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

Answers:

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.