Skip to content

Selector bounded to a circle #153

@lawloretienne

Description

@lawloretienne

If I try to add this attribute
android:foreground="?android:attr/selectableItemBackground"
to a CircleImageView then when I click on the view the ripple is bounded to a square instead of a circle. How can you change that behavior?

Activity

hdodenhof

hdodenhof commented on Sep 26, 2016

@hdodenhof
Owner

You need to create your own selector drawable to mask that ripple effect.
Something like this (untested):

<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="128dp"
    android:layout_height="128dp"
    android:src="@drawable/foobar"
    android:foreground="@drawable/my_selector"
    android:clickable="true"/>

drawable-v21/my_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?attr/colorControlHighlight">
    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <solid android:color="#ffffff"/>
        </shape>
    </item>
</ripple>

drawable/my_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/circle" android:state_pressed="true"/>
    <item android:drawable="@android:color/transparent"/>
</selector>

drawable/circle.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval">
    <solid android:color="?attr/colorControlHighlight"/>
</shape>
idedalusse

idedalusse commented on Aug 23, 2019

@idedalusse

Hi, I have a problem with the following message
java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to androidx.core.widget.NestedScrollView

i am in androidx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lawloretienne@hdodenhof@idedalusse

        Issue actions

          Selector bounded to a circle · Issue #153 · hdodenhof/CircleImageView