2
我想將我的CardView的前景設置爲?attr/selectableItemBackground
。將SelectableItemBackground添加到CardView
它工作時,我宣佈在前景XML的:
android:foreground="?attr/selectableItemBackground"
但我想以編程方式設置的前景。這不起作用:
int[] attrs = new int[]{R.attr.color_a, R.attr.selectableItemBackground};
TypedArray ta = context.obtainStyledAttributes(attrs);
mColorA = ta.getColor(0, 0);
mSelectableItemBackground = ContextCompat.getDrawable(context, ta.getResourceId(1, 0));
ta.recycle();
...
cardView.setOnClickListener(onClickListener);
cardView.setClickable(true);
cardView.setForeground(mSelectableItemBackground);
然而,檢索屬性作品(mSelectableItemBackground包含RippleDrawable
),但是當我按下插卡的前景不會改變。
我想我只是在這裏找到了一個可能的解決方案:http://stackoverflow.com/q/27474279/4752807 ..我也在多個卡上使用相同的實例..我必須調查,然後將更新此問題。 – Auroratic
你見過這個答案嗎? http://stackoverflow.com/a/30192562/4409409 –