Skip to content

Instantly share code, notes, and snippets.

@joesteele
Last active February 5, 2021 14:58
Show Gist options
  • Save joesteele/cb86986a5c56d1db5c9f to your computer and use it in GitHub Desktop.
Save joesteele/cb86986a5c56d1db5c9f to your computer and use it in GitHub Desktop.
Ripple when view has alpha background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#66000000"/>
<corners android:radius="4dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/black"/>
<corners android:radius="4dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#316C41"/>
<corners android:radius="4dp"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<!-- Ripple effect does not work, but the drawable background does -->
<!-- http://d.pr/i/1fQTf -->
<ripple android:color="#1A000000" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_alpha_bg" />
</ripple>
<?xml version="1.0" encoding="utf-8"?>
<!-- Ripple effect works, but the drawable background is gone -->
<!-- http://d.pr/i/15hka -->
<ripple android:color="#1A000000" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/mask" android:drawable="@drawable/btn_alpha_bg" />
</ripple>
<?xml version="1.0" encoding="utf-8"?>
<!-- Ripple effect does work as well the drawable background -->
<!-- http://d.pr/i/1lEb9 -->
<ripple android:color="#1A000000" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_normal_bg" />
</ripple>
<?xml version="1.0" encoding="utf-8"?>
<!-- WORKING SOLUTION -->
<!-- Ripple effect does work as well as the alpha drawable background -->
<ripple android:color="#1A000000">
<item android:id="@android:id/mask" android:drawable="@drawable/btn_mask"/>
<item android:drawable="@drawable/btn_alpha_bg" />
</ripple>
@mrstif
Copy link

mrstif commented Feb 5, 2021

🙏 big thanks. this was driving me mad

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