【问题标题】:How to remove shadow from Appbar and add shadow to the TabLayout如何从 Appbar 中移除阴影并将阴影添加到 TabLayout
【发布时间】:2019-04-10 21:47:24
【问题描述】:

我有以下带有 3 个标签的简单应用程序:

我想从 appbar 中移除阴影并将阴影添加到 tablayout。 我尝试了多种方法,例如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>

【问题讨论】:

标签: android


【解决方案1】:

在AppBarLayout 中添加Elevation,如下所示

getSupportActionBar().setElevation(0);

为您的选项卡布局添加阴影只需为您的选项卡布局添加高程。以及阅读信息 Material-Design.

android:background="?attr/colorPrimary"
android:elevation="15dp"

【讨论】:

  • 谢谢,这消除了阴影,但是如何将阴影添加到选项卡?没有任何效果。顺便说一句,AppBarLayout 是什么意思?我只是在onCreate 里面的主要活动中写了它
  • 嗨@Fireio 抱歉回复晚了...请检查答案。
猜你喜欢
  • 2015-10-11
  • 2017-09-08
  • 2012-01-18
  • 2016-09-16
  • 2018-08-07
  • 1970-01-01
  • 2017-09-01
  • 2021-10-30
  • 1970-01-01
相关资源
最近更新 更多