Android Toobar在TabLayout上投下阴影

Android Toobar在TabLayout上投下阴影,android,android-fragments,material-design,android-toolbar,android-tablayout,Android,Android Fragments,Material Design,Android Toolbar,Android Tablayout,大家好!我在活动中的FrameLayout容器中有一个片段,它具有导航抽屉。碎片已展开。问题是,正如你所看到的那样 活动的工具栏在片段的TabLayout上投下阴影。我不想将TabLayout放在活动的AppBar布局中,因为我无法从fragment访问它,而且,我在其他任何地方都不需要该TabLayout 这是我的活动\u main.xml <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encodin

大家好!我在活动中的FrameLayout容器中有一个片段,它具有导航抽屉。碎片已展开。问题是,正如你所看到的那样 活动的工具栏在片段的TabLayout上投下阴影。我不想将TabLayout放在活动的AppBar布局中,因为我无法从fragment访问它,而且,我在其他任何地方都不需要该TabLayout

这是我的
活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>

我还希望在ViewPager中向上滚动片段列表时隐藏工具栏


你有什么办法可以做到这一点吗?

你需要确保所有东西都有相同的高度。

使用这个。负责我的项目

ViewCompat.setElevation(mAppBarLayout, 0);
第二个问题是如何隐藏工具栏? 将父布局linearlayout更改为layout

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <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:id="@+id/loginToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <FrameLayout
        android:id="@+id/mainFragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>

支持库v24.0.0中的AppBarLayout使用
StateListAnimator
。如果在此新版本中使用,则设置appBayLayout.setElevation(0)将无效

相反,请尝试在
StateListAnimator
中将标高设置为0,如下所示,以便
Build.VERSION.SDK\u INT>=21

StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0));
appBarLayout.setStateListAnimator(stateListAnimator);

从支持库v24.0.0
AppBarLayout
使用
StateListAnimator
设置高程。要获得与24.0.0之前版本相同的行为,只需将animator设置为null并调用
setElevation()


我不想使用
提升
,因为它在棒棒糖前不起作用,我不确定这是一个想要/不想要的场景。。。阴影是从立面绘制的。如果不需要阴影,则应将高程指定为0。尽管如此,这将使你的设计变得平坦,并与使用表面的材料设计语言模式相矛盾。只是在棒棒糖前尝试了一下,效果不错,但在API 21+上不起作用。无效(是什么让你认为如果你把它放在工具栏中,你将无法从片段中访问tablayout?老实说,我认为将选项卡放在工具栏中是一种更好、更广泛理解的模式。当你向上移动viewpager时,你还可以达到隐藏工具栏的效果。再次检查我的答案。我为你更新了r第二个问题。从不知道ViewCompat.setElevation()
ViewCompat.setElevation(mAppBarLayout, 0);
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <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:id="@+id/loginToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <FrameLayout
        android:id="@+id/mainFragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

 <android.support.design.widget.TabLayout
     android:id="@+id/byDayTabLayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:tabBackground="?attr/colorPrimary"
     app:tabMode="scrollable" />

<android.support.v4.view.ViewPager
    android:id="@+id/byDayViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0));
appBarLayout.setStateListAnimator(stateListAnimator);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    appbarLayout.setStateListAnimator(null);
}

ViewCompat.setElevation(appbarLayout, 0);