AppBarLayout背景圆角

lea*_*ner 5 android android-layout

我正在为我的应用程序实现自定义标头。在 AppBarLayout 中,我使用 Toolbar 和自定义布局(名为 CustomHeader)。我的 CustomHeader 有左下角和右下角圆角。为了正确显示我设置了android:background="@null".

具有自定义标题的 appBarLayout 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/logoAppbarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        android:elevation="@dimen/_4sdp">

        <android.support.v7.widget.AppCompatImageView
            android:id="@+id/imgToolbarLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/ic_toolbar_logo" />
    </android.support.v7.widget.Toolbar>

    <CustomHeader
        android:id="@+id/stepOneHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00FFFFFF"
        app:selected_step="1"/>

    <ProgressBar
        android:id="@+id/stepProgressBar"
        style="@style/AppTheme.StepProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:progress="0"
        android:visibility="gone" />

</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的 CustomHeader 的布局。为了简洁起见,我省略了一些部分:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/header_bg">
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_marginStart="@dimen/_18sdp"
        android:layout_marginEnd="@dimen/_18sdp"
        android:layout_marginTop="@dimen/_12sdp"
        android:layout_marginBottom="@dimen/_12sdp">

        <View
            android:id="@+id/headerDivider"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_2sdp"
            android:background="@drawable/bg_divider_border"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

            ...
    </android.support.constraint.ConstraintLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是CustomHeader的背景:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:width="2dp"
        android:color="@color/colorPrimary" />
    <corners
        android:bottomLeftRadius="22dp"
        android:bottomRightRadius="22dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

发生的事情是:无论我做什么,在 AppBarLayout 底部边框上我总是有一个白色背景。图片如下: 白角

请注意,屏幕在标题之后继续。

我尝试了基于SO的2个解决方案: 带有圆角边缘的ActionBar 如何在appbarlayout内制作带有圆角和高程的工具栏?喜欢这张照片

我的问题与第二个链接几乎相同。他们中的任何一个都为我工作。我只想要这个白色背景透明。

小智 1

将此行添加到 AppBarLayout xml:

应用程序:海拔=“0dp”