How to set Ripple effect on a LinearLayout programmatically? How to set Ripple effect on a LinearLayout programmatically? android android

How to set Ripple effect on a LinearLayout programmatically?


You can use this way.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {    // If we're running on Honeycomb or newer, then we can use the Theme's    // selectableItemBackground to ensure that the View has a pressed state    TypedValue outValue = new TypedValue();    this.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);    textView.setBackgroundResource(outValue.resourceId);}