Android – удалить тень между панелью инструментов и TabLayout

Я пытаюсь сделать макет с помощью CollapsingToolbarLayout. Но я не понимаю одного. Я хочу удалить тень между панелью инструментов и вкладкой. Я пробовал несколько способов, и мне не удалось удалить тень. Кто-нибудь может мне помочь? Спасибо

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/adview"
    android:fitsSystemWindows="true">

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="50dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <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
        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.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/detalle_info_fab_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="false"
        android:src="@drawable/ic_check1"
        app:fabSize="mini"
        app:backgroundTint="@android:color/white"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />

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

<include
    android:id="@+id/adview"
    layout="@layout/adview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />




Ответы (4)


Попробуйте установить app:elevation="0dp" (не android:elevation) для AppBarLayout.

Если у вас нет пространства имен приложения в xml, добавьте xmlns:app="http://schemas.android.com/apk/res-auto".

Разницу между этими двумя свойствами можно найти здесь.

После этого убедитесь, что вы не добавляете какой-либо фон/границу ни с одним из этих свойств:

 <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"/>

Или тему, которую вы используете для AppBarLayout.

person RominaV    schedule 26.05.2016
comment
Ваш код работает наполовину. Теперь между Toolbar и TabLayout отображается линия (не тень). - person IMS; 26.05.2016
comment
@IMS отредактировал ответ. Проверьте цвета и тему, которые вы устанавливаете для этих представлений. - person RominaV; 26.05.2016
comment
@RominaV у меня не работает. Пожалуйста, помогите stackoverflow. ком/вопросы/63658694/ - person Sophia Gray; 30.08.2020

<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" />

Используйте app:elevation="0dp", чтобы удалить тень. Это всегда работало для меня. Надеюсь, это сработает для вас.

А также программно,

appBar.setOutlineProvider(null);
person Ajay Yadav    schedule 08.05.2018

Вы должны поместить панель инструментов и TabLayout в один и тот же 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>

Взгляните на эту ошибку.

person cklar    schedule 22.12.2016

Я знаю, что на вопрос уже дан ответ. Но я хочу поделиться тем, чему я научился на собственном горьком опыте, чтобы люди, столкнувшиеся с теми же проблемами, могли сэкономить время.

Вам нужно обернуть AppBarLayout внутри CoordinatorLayout иначе app:elevation не будет работать.

Рабочий пример:

<CoordinatorLayout>
    <AppBarLayout>
        <Toolbar>
person flamyoad    schedule 26.10.2019