2016-06-23 9 views

उत्तर

50

लिए appcompat आप उपयोग कर सकते हैं,

TypedValue outValue = new TypedValue(); 
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); 
cardView.setBackgroundResource(outValue.resourceId); 
+0

सहायक लिंक, धन्यवाद! –

+0

मैं बहुत कुछ खोज रहा हूं और मुझे बहुत सारे जवाब मिल गए हैं, लेकिन यह निश्चित रूप से सबसे अच्छा है। आपको बहुत - बहुत धन्यवाद! –

0

कोड नीचे आज़माएं।

int[] attrs = new int[]{R.attr.selectableItemBackground}; 
TypedArray typedArray = context.obtainStyledAttributes(attrs); 
int backgroundResource = typedArray.getResourceId(0, 0); 
cardView.setBackgroundResource(backgroundResource); 
cardView.setClickable(true); 
typedArray.recycle(); 
+0

मुझे खेद है, लेकिन यह कोड मुझे समझ में नहीं आता है, अगर आपको इससे कोई संसाधन नहीं मिल रहा है तो 'टाइपेडअरे' प्राप्त करने का क्या मतलब है? –

0

मैं एक ही समाधान के लिए देख रहा था यह उल्लेख होना चाहिए। मैंने थोड़ा प्रश्न this उत्तर दिया ताकि यह पूछे जाने वाले प्रश्न के लिए अधिक उपयुक्त हो सके। अपने कन्स्ट्रक्टर से निम्नलिखित कोड पर कॉल करें।

private void setClickableAnimation(Context context) 
{ 
    TypedValue outValue = new TypedValue(); 
    context.getTheme().resolveAttribute( 
     android.R.attr.selectableItemBackground, outValue, true);   
    setForeground(getDrawable(context, outValue.resourceId)); 
} 
संबंधित मुद्दे