android - 如何在android中将底部阴影添加到选项卡布局或工具栏

标签 android xml toolbar shadow android-elevation

您好,我需要在我的选项卡布局下添加阴影(就像在 Skype 中一样)。

shadow_skype

我的 Activity xml:

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/splashGreenTop"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="0dp"
        android:minHeight="?attr/actionBarSize" />
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/tab_layout"
        android:id="@+id/tabContainer"
        android:layout_height="match_parent" />
</RelativeLayout>

当我将 android:elevation="10dp" 添加到 Tablayout 时,阴影被添加到底部和顶部。我只需要底部。看图...

enter image description here

我该怎么做? 提前致谢。

最佳答案

只需将高度添加到您的 Tablayout (0dp - 25dp)。阅读 material design有关海拔的更多信息的指南。

android:elevation="10dp"

编辑:
将它添加到您的 tablayout 和工具栏

<android.support.v7.widget.Toolbar xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/splashGreenTop"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:elevation="10dp" />
<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_below="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize" 
    android:elevation="10dp"/>

关于android - 如何在android中将底部阴影添加到选项卡布局或工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34675791/

相关文章:

Android:使用选项卡在不同 fragment 之间切换

android - 未指定大小时 PopupWindow 超出屏幕

java - TCP:如何从 Android 客户端中的 Vb.net 服务器获得响应?

android - 来自 keystore 的 key 的编码文本在 android M 中为空

android - 如何在android中的一个按钮中放置2个不同的文本?

button - Hybris HMC : adding a button to ToolBarChip/Editor window next to the save button

java - 如何创建一个包含 ViewPager 的折叠工具栏?

android - 如何在开发过程中找到应用程序的大小

c# - 如何获取具有特定主题标签值的注释节点

xml - Powershell 空 XML 元素格式化为一行