gpt4 book ai didi

java - Android Studio中的Card View添加点击效果波纹效果

转载 作者:行者123 更新时间:2023-12-02 09:20:52 25 4
gpt4 key购买 nike

我已以编程方式添加了卡片 View 。我只是想让它可点击并在点击时显示动画。这是我的代码

CardView cardView = new CardView(this);
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
cardView.setLayoutParams(layoutParams);
cardView.setRadius(15);
cardView.setPadding(25, 25, 25, 25);
cardView.setCardBackgroundColor(Color.MAGENTA);

TextView textView = new TextView(this);
textView.setLayoutParams(layoutParams);
textView.setText("Programmatically set");
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.WHITE);
cardView.addView(textView);
LinearLayout linearLayout = findViewById(R.id.linearLayout1);
linearLayout.addView(cardView);

最佳答案

int[] attrs = new int[]{R.attr.selectableItemBackground};
TypedArray typedArray = this.obtainStyledAttributes(attrs);
int selectableItemBackground = typedArray.getResourceId(0, 0);
typedArray.recycle();

cardView.setForeground(this.getDrawable(selectableItemBackground));
cardView.setClickable(true);

关于java - Android Studio中的Card View添加点击效果波纹效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com