CardView 背景在更改可见性时发生变化?
CardView background changing when changing visibility?
我必须在点击 点击编辑文本 TextView
时显示 CardView
,点击外部将隐藏 CardView
。为此,我尝试将 CardView
背景切换为透明和白色,但它不起作用。然后我尝试将包含字母的 EditText
和 CardView
都放在 FrameLayout
中,然后隐藏并显示 CardView
但是 CardView
背景样式变为透明,同时做过某事。
您可以在下面找到我的 xml。
请告诉我这里发生了什么?
XML
<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>
代码
private void controlView() {
mCard.setVisibility(View.VISIBLE);
mNote.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
mNote.setCursorVisible(true);
mNote.setSelection(mNote.length());
}
尝试使用
mCard.setCardBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
要以编程方式更改 cardview 的颜色,您可以使用:
mCard.setCardBackgroundColor(Color.TRANSPARENT);
在 XML
中完成
mCard:cardBackgroundColor="@android:color/transparent"
我必须在点击 点击编辑文本 TextView
时显示 CardView
,点击外部将隐藏 CardView
。为此,我尝试将 CardView
背景切换为透明和白色,但它不起作用。然后我尝试将包含字母的 EditText
和 CardView
都放在 FrameLayout
中,然后隐藏并显示 CardView
但是 CardView
背景样式变为透明,同时做过某事。
您可以在下面找到我的 xml。
请告诉我这里发生了什么?
XML
<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>
代码
private void controlView() {
mCard.setVisibility(View.VISIBLE);
mNote.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
mNote.setCursorVisible(true);
mNote.setSelection(mNote.length());
}
尝试使用
mCard.setCardBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
要以编程方式更改 cardview 的颜色,您可以使用:
mCard.setCardBackgroundColor(Color.TRANSPARENT);
在 XML
中完成mCard:cardBackgroundColor="@android:color/transparent"