How to set Ripple effect on a LinearLayout programmatically?

后端 未结 1 845
小蘑菇
小蘑菇 2020-12-02 11:15

I want to set the background android.R.attr.selectableItemBackground to a LinearLayout. When using XML there are no problems (it works)

<         


        
1条回答
  •  遥遥无期
    2020-12-02 11:56

    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);
    }
    

    0 讨论(0)
提交回复
热议问题