Java – FrameLayout foreground with selector

I have a FrameLayout. I want to apply the foreground drawable through the selector. I try to implement "drawselectorontop", but it is a simple layout

Now, when the user presses "state_pressed", the selector does not apply

This 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 selection 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 FrameLayout always applies the normal state drawable as the foreground

Solution

The old problem, but when I encountered a similar problem, it was Google's first blow

Do you have an onclick listener set for FrameLayout? If not, the pressed state will never be used

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>