Android - Remove shadow between Toolbar and TabLayout

瘦欲@ 提交于 2019-11-30 07:18:34
RominaV

Try setting app:elevation="0dp" (not android:elevation) for your AppBarLayout.

In case you don't have the app namespace in your xml, add xmlns:app="http://schemas.android.com/apk/res-auto".

The difference between these two properties can be found here.

After that, check that you're not adding some background/border with any of these properties:

 <android.support.design.widget.TabLayout
    android:background="?attr/colorPrimary"
    android:translationZ="2dp"
    app:layout_anchor="@+id/appbar"
    app:layout_anchorGravity="bottom"
    app:tabGravity="fill"
    app:tabIndicatorColor="@android:color/white"/>

Or the theme you're using for the AppBarLayout.

<android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            app:titleTextColor="@android:color/white" />

    </android.support.design.widget.AppBarLayout>

<include layout="@layout/content_tablayout" />

Use app:elevation="0dp" to remove the shadow. It has always worked for me. Hope it works for you.

And also by programatically,

appBar.setOutlineProvider(null);

You have to put the Toolbar and the TabLayout in the same AppBarLayout

    <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="20dp"
        app:expandedTitleMarginStart="20dp"
        app:expandedTitleTextAppearance="@style/detalle_txt_expanded"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/detalle_img"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/img_thumb_m"
            android:transitionName="@string/transition"
            app:layout_collapseMode="parallax"
            tools:targetApi="lollipop" />

        <ImageView
            android:id="@+id/detalle_img_tipo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/img_edificio"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme"/>

    </net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom"
        android:background="?attr/colorPrimary"
        android:translationZ="2dp"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom"
        app:tabGravity="fill"
        app:tabIndicatorColor="@android:color/white"
        app:tabIndicatorHeight="3dp"
        app:tabMode="fixed"
        app:tabTextColor="@color/tabs_text_selector" />

</android.support.design.widget.AppBarLayout>

Take a look at this issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!