3

我的 CardView 一直按预期显示,直到像这样的android O ,

但是在android P中它看起来像这样,(里面是透明的白色矩形)

这是应用程序所有 CardView 中使用的样式。

 <style name="translucentCard" parent="CardView">
        <item name="cardCornerRadius">20dp</item>
        <item name="cardBackgroundColor">#26ffffff</item>
 </style>

如果我使用不透明cardBackgroundColor,则内部矩形会消失,但这不是解决方案。我需要使用以前使用的半透明颜色。任何人都可以帮我克服这个吗?请注意,它只发生在Android Pie中。

4

4 回答 4

4

最新版本的向后兼容海拔

app:cardElevation="0dp"

或者

<item name="cardElevation">0dp</item>
于 2018-08-07T09:09:03.313 回答
0

使用这个希望这会起作用:

<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>
于 2018-06-11T11:19:08.147 回答
0

尝试设置

android:background="@null"

到 CardView 内的 LinearLayout 或此 LinearLayout 内的 TextViews。

这样,您将完全删除背景,因此不会有任何透支。

于 2018-06-11T11:28:09.327 回答
0

添加这个

android:outlineSpotShadowColor="@color/colorGray"
android:outlineAmbientShadowColor="@color/colorGray"

这解决了我的问题。使用透明度低的灰色

于 2019-09-02T04:34:14.540 回答