Cardview 中的 CardCornerRadius 在 android Pie 中看起来很奇怪
CardCornerRadius in cardview looking weird in android Pie
我的 CardView 一直按预期显示,直到 android O 像这样,
但是在androidP里面是这样的,(里面是透明的白色矩形)
本应用所有CardView均采用该样式。
<style name="translucentCard" parent="CardView">
<item name="cardCornerRadius">20dp</item>
<item name="cardBackgroundColor">#26ffffff</item>
</style>
如果我使用不透明 cardBackgroundColor
那么内部矩形就会消失,但这不是解决方案。我需要像以前一样使用半透明颜色。谁能帮我克服这个问题吗?请注意,它只发生在 Android Pie.
使用这个希望这会起作用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="...">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="..." />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
style="@style/translucentCard"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_height="wrap_content">
<LinearLayout
style="@style/paddedContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_email">
<EditText
android:id="@+id/.."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:padding="8dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_password">
<EditText
android:id="@+id/editTextPasswordForLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:padding="8dp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewForgotPassword"
style="@style/WarrentyLifeTheme.TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login_forgot_password" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="@dimen/buttonHeight"
android:paddingLeft="36dp"
android:paddingRight="36dp"
android:text="@string/dashboard_button_login" />
</LinearLayout>
尝试设置
android:background="@null"
CardView 内的 LinearLayout 或此 LinearLayout 内的 TextView。
这样您将完全删除背景,因此不会有任何透支。
最新版本的向后兼容提升
app:cardElevation="0dp"
或
<item name="cardElevation">0dp</item>
添加这个
android:outlineSpotShadowColor="@color/colorGray"
android:outlineAmbientShadowColor="@color/colorGray"
This solved my problem. Use gray color with a low transparency
我的 CardView 一直按预期显示,直到 android O 像这样,
但是在androidP里面是这样的,(里面是透明的白色矩形)
本应用所有CardView均采用该样式。
<style name="translucentCard" parent="CardView">
<item name="cardCornerRadius">20dp</item>
<item name="cardBackgroundColor">#26ffffff</item>
</style>
如果我使用不透明 cardBackgroundColor
那么内部矩形就会消失,但这不是解决方案。我需要像以前一样使用半透明颜色。谁能帮我克服这个问题吗?请注意,它只发生在 Android Pie.
使用这个希望这会起作用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="...">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="..." />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
style="@style/translucentCard"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_height="wrap_content">
<LinearLayout
style="@style/paddedContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_email">
<EditText
android:id="@+id/.."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:padding="8dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_password">
<EditText
android:id="@+id/editTextPasswordForLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:padding="8dp" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewForgotPassword"
style="@style/WarrentyLifeTheme.TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/login_forgot_password" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="@dimen/buttonHeight"
android:paddingLeft="36dp"
android:paddingRight="36dp"
android:text="@string/dashboard_button_login" />
</LinearLayout>
尝试设置
android:background="@null"
CardView 内的 LinearLayout 或此 LinearLayout 内的 TextView。
这样您将完全删除背景,因此不会有任何透支。
最新版本的向后兼容提升
app:cardElevation="0dp"
或
<item name="cardElevation">0dp</item>
添加这个
android:outlineSpotShadowColor="@color/colorGray"
android:outlineAmbientShadowColor="@color/colorGray"
This solved my problem. Use gray color with a low transparency