When user click in the app, i need to show ripple effect on button after click perform but i need to apply this programmatically.
Asked
Active
Viewed 30 times
-1
-
If you're just asking how to do a ripple effect, see https://stackoverflow.com/questions/26604134/how-to-achieve-ripple-animation-using-support-library – Gabe Sechan Dec 05 '18 at 14:01
-
Did you take a look to this article? https://medium.com/@sajidhzazahir/android-ripple-effect-with-background-drawable-programmatically-1128d92a21b3 – Nicola Gallazzi Dec 05 '18 at 14:29
1 Answers
0
You could try something like this:
yourBtn = findViewById(R.id.your_btn);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TypedValue outValue = new TypedValue();
getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
yourBtn.setForeground(getResources().getDrawable(outValue.resourceId, null));
}
If you didn't set a specific background for your button, then you also use this code snippet:
startSearchBtn = findViewById(R.id.start_search_btn);
TypedValue outValue = new TypedValue();
getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
startSearchBtn.setBackgroundResource(outValue.resourceId);

Benjamin Menrad
- 898
- 10
- 14