简体   繁体   中英

How to maintain ripple effect when the button is selected

I have a button with ripple effect, it has two states one is "regular" with ripple effect and the other one is selected the background is changed but there are two issues:

  1. The hole button colored with color, I would like only to color the oval shape of the button
  2. The ripple effect not persist when changing the background color of the button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_selected="true" android:drawable="@color/cal_selected"/>
    <item android:drawable="@drawable/cal_day_regualr">
        <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:attr/colorActivatedHighlight">
            <item android:id="@android:id/mask">
                <shape android:shape="oval">
                    <solid android:color="@color/cal_background" />
                </shape>
            </item>
        </ripple>
    </item>
</selector>

I managed to accomplish this by adding another ripple to selected state see the code below:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true">

        <ripple android:color="@color/cal_selected_ripple">
            <item>
                <shape android:shape="oval">
                    <solid android:color="@color/cal_selected" />
                </shape>
            </item>
        </ripple>

    </item>
    <item>
        <ripple android:color="?android:attr/colorActivatedHighlight">
            <item android:id="@android:id/mask">
                <shape android:shape="oval">
                    <solid android:color="@color/cal_background" />
                </shape>
            </item>
        </ripple>
    </item>
</selector>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM