首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CardView背景变化时可见性变化?

CardView背景变化时可见性变化?
EN

Stack Overflow用户
提问于 2016-04-01 08:31:43
回答 2查看 549关注 0票数 0

我必须显示CardView时,录音的Tap来编辑文本 TextView和点击外部将隐藏CardView。为了做到这一点,我尝试将CardView背景切换为透明和白色,但它没有工作。然后,我尝试将包含字母的EditTextCardView放在FrameLayout中,然后隐藏并显示CardView,但是CardView的背景样式在这样做时会变成透明的。您可以在下面找到我的xml。请告诉我这里发生了什么事?

XML

代码语言:javascript
复制
<FrameLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="@dimen/margin_padding_2">

<android.support.v7.widget.CardView
  android:id="@+id/cardView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="0dp"
  app:cardCornerRadius="@dimen/box_radius"
  app:cardElevation="0dp"
  app:contentPadding="@dimen/margin_padding_2" />

<com.package.views.EditText
  android:id="@+id/note"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@null"
  android:cursorVisible="false"
  android:gravity="start"
  android:lineSpacingExtra="@dimen/margin_padding_1"
  android:padding="@dimen/margin_padding_2"
  android:textColor="@color/colorWhite"
  android:textSize="@dimen/text_size_5"
  app:textStyle="bold" />

</FrameLayout>

代码语言:javascript
复制
 private void controlView() {
        mCard.setVisibility(View.VISIBLE);
        mNote.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
        mNote.setCursorVisible(true);
        mNote.setSelection(mNote.length());
 }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-01 09:05:19

试着使用

代码语言:javascript
复制
mCard.setCardBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
票数 2
EN

Stack Overflow用户

发布于 2016-04-01 09:24:17

若要以编程方式更改硬视图的颜色,您可以使用:

代码语言:javascript
复制
mCard.setCardBackgroundColor(Color.TRANSPARENT);

在XML中执行

代码语言:javascript
复制
mCard:cardBackgroundColor="@android:color/transparent"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36351605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档