如何删除默认顶部工具栏和TabBar之间的阴影安卓系统

时间:2018-10-18 22:29:05

标签: android android-studio material-design android-designer

任何人都请帮忙,我是android的新手,我需要删除工具栏和TabBar之间的阴影。我已经尝试了多种在线解决方案,但是我无法正常使用.....请帮助我...

参考图片 enter image description here

活动XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorIce"
    android:fadeScrollbars="true"
    android:isScrollContainer="true"
    tools:context=".HomeActivity">
    <android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
    android:layout_width="match_parent"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        style="@android:style/Widget.Material.ActionBar.TabBar"
        android:layout_width="match_parent"
        android:layout_height="50sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
        <android.support.design.widget.TabItem
            android:id="@+id/tabItem"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/tab_text_1" />
        <android.support.design.widget.TabItem
            android:id="@+id/tabItem2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/tab_text_2" />
    </android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/container1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="-1dp"
        android:layout_marginEnd="-1dp"
        android:elevation="0sp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

使用AppBarLayout包装工具栏

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >
    <android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>

在styles.xml中添加样式

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="elevation">0dp</item>
</style>