What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)
Use 26% alpha for colored ripples.
Android L doesn't support theme attributes in color state lists and the <ripple>
element doesn't have an alpha channel, but for bounded ripples you can do something like:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorAccent">
<item android:id="@android:id/mask">
<color android:color="#42ffffff" />
</item>
</ripple>
This won't work for an unbounded ripple. Alternatively, since you know your own accent color, you can either define a 26% alpha version or use a color state list. Either of these will work fine for an unbounded ripple.
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/accent_26" />
res/values/colors.xml:
<resources>
...
<color name="accent">#ff33b5e5</color>
<color name="accent_alpha26">#4233b5e5</color>
</resources>
res/color/accent_alpha26.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/accent"
android:alpha="0.26" />
</selector>
Changing color of Ripple Effect
You can set this as your views background:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorAccent">
<item android:id="@android:id/mask">
<color android:color="#42ffffff" />
</item>
For more details see this question on stackoverflow:
What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)
And you can use this library for lower apis:
https://github.com/traex/RippleEffect
Material Components Default to colorAccent instead of colorPrimary
Use the Material Components Library 1.1.0 or later.
The default style of the MaterialButton
is:
<style name="Widget.MaterialComponents.Button" parent="Widget.AppCompat.Button">
<item name="backgroundTint">@color/mtrl_btn_bg_color_selector</item>
<!-- .... -->
</style>
Starting from the version 1.1.0
the @color/mtrl_btn_bg_color_selector
is based on the ?attr/colorPrimary
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_enabled="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>
In the version 1.0.0
the selector was based on ?attr/colorAccent
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorAccent" android:state_enabled="true"/>
<item android:color="@color/mtrl_btn_bg_color_disabled"/>
</selector>
How to use light ripple on Material Button in Android
Yes, there is the way.
Create xml (button.xml for example):
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/white">
<item android:drawable="@drawable/button_ripple" />
</ripple>
Create button_ripple.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="200dp"
android:height="50dp"/>
<solid
android:color="@color/accent" />
</shape>
Change android:color="@android:color/white" in button.xml to needed color for ripple effect and assign button.xml as a background to your button.
@color/accent is the normal state button color.
Related Topics
Displaying Contact Number and Contact Name in a Custom List View
Notifydatasetchanged Not Working on Recyclerview
My App Was Rejected by Instagram Basic Display API Review Due to Invalid Reasons
Best Way to Save Large Amount of Data Locally in Unity3D Android
Which Port and Protocol Does Google Cloud Messaging (Gcm) Use
Using Intent.Action_Pick for Specific Path
Android Supporting Multiple Resolution with Multiple Layout Folder
Android - Detecting Application Launch from Home or History
Bitmap Too Large to Be Uploaded into a Texture
Android: How to Change the Datepicker View Date Format from Mm/Dd/Yyyy to Dd/Mm/Yyyy
Http Post Method Passing Null Values to the Server
How to Implement a Gcm Hello World for Android Using Android Studio
Batch Scripting - If Exist ./Sdcard/File.Any Using Adb
How to Fill Recyclerview with Gridlayoutmanager from Right to Left
Writing/Reading Files To/From Android Phone's Internal Memory