如何从Appbar删除阴影并将阴影添加到TabLayout

时间:2018-11-19 12:23:03

标签: android

我有以下带有3个标签的简单应用: simple app

我想从应用栏中删除阴影并将阴影添加到布局中。 我尝试了多种操作,例如android:elevation或将<item name="elevation">0dp</item>添加到AppTheme,或使用<item name="android:windowContentOverlay">@null</item>。什么都没有。我在应用程序栏(我的应用程序在下面)下一直有阴影,并且没有在阴影下添加阴影 标签(第1页,第2页,第3页在哪里)。

这些是我的xml文件:

style.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="elevation">0dp</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <!-- Style for a tab that displays a category name -->
    <style name="CategoryTab" parent="Widget.Design.TabLayout">
        <item name="tabIndicatorColor">@android:color/white</item>
        <item name="tabSelectedTextColor">@android:color/holo_purple</item>
        <item name="tabTextAppearance">@style/CategoryTabTextAppearance</item>
    </style>
    <!-- Text appearance style for a category tab -->
    <style name="CategoryTabTextAppearance" parent="TextAppearance.Design.Tab">
        <item name="android:textColor">#000000</item>
    </style>
</resources>

这是activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color"
    android:orientation="vertical"
    tools:context="com.example.barebones.barebones.MainActivity">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        style="@style/CategoryTab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="15dp"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="10dp"/>

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

像下面一样在Elevation中添加AppBarLayout

getSupportActionBar().setElevation(0);

将阴影添加到布局中,只需将高程添加到布局中即可。还有信息阅读 Material-Design

android:background="?attr/colorPrimary"
android:elevation="15dp"
相关问题