Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selector bounded to a circle #153

Closed
lawloretienne opened this issue Sep 13, 2016 · 3 comments
Closed

Selector bounded to a circle #153

lawloretienne opened this issue Sep 13, 2016 · 3 comments

Comments

@lawloretienne
Copy link

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?

@hdodenhof
Copy link
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>

@raiarainne
Copy link

Thank you for great Great solution.
It is very helpful for me.
Best Regards.

@idedalusse
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants