首页 > 解决方案 > 以编程方式将 strokeColor 设置为 CardView

问题描述

我正在尝试strokeColor以编程方式设置,但它不起作用。这是我尝试过的

gold_card.strokeColor= Color.GREEN

查看strokeColor的官方方法,它需要一个参数

public void setStrokeColor(@ColorInt int strokeColor) {
    this.cardViewHelper.setStrokeColor(strokeColor);
}

因此,在传递 Color int 参数时,它表示无法访问代码。下面的方法说无法访问的代码

gold_card.strokeColor(Color.GRAY)

那么如何设置strokeColorCardView正确的方式呢?PS:是的,我正在使用MaterailCardView

标签: androidkotlinandroid-cardviewmaterialcardview

解决方案


您需要定义gold_cardMatericalCardView,而不是CardView

MatrialCardView gold_card = findViewById(R.id.cold_card)

推荐阅读