首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在android中添加底部阴影到选项卡布局或工具栏

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

Stack Overflow用户
提问于 2016-01-08 19:17:23
回答 4查看 26.6K关注 0票数 16

嗨,我需要添加阴影下我的标签布局(如在skype)。

我的活动xml:

代码语言:javascript
复制
    <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"添加到表格布局时,阴影被添加到底部和顶部。我需要的只是底部。如图所示...

我该怎么做呢?提前谢谢。

EN

回答 4

Stack Overflow用户

发布于 2017-04-15 11:01:36

实际上有一个非常简单的解决方案:只需将工具栏和TabLayout放在AppBarLayout中即可。例如:

代码语言:javascript
复制
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ToolbarTheme"
        app:titleTextAppearance="@style/ThemeOverlay.AppCompat.ActionBar"
        android:background="@color/colorPrimary"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>

这对我来说非常有效,也是将应用程序/工具栏和TabLayout结合在一起的常用方式。

票数 2
EN

Stack Overflow用户

发布于 2021-09-20 04:59:17

只需添加一行,它就可以工作了。

代码语言:javascript
复制
   android:elevation="5dp"

查看完整代码:

代码语言:javascript
复制
   <com.google.android.material.tabs.TabLayout
    android:id="@+id/tabLayoutSave"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:elevation="5dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="parent"
    app:tabIndicatorColor="#1d1d1f"
    app:tabIndicatorHeight="4dp"
    app:tabMode="fixed"
    app:tabSelectedTextColor="#1d1d1f"
    app:tabTextColor="#888888" />
票数 1
EN

Stack Overflow用户

发布于 2017-01-05 20:13:04

将标高添加到Tablayout中。Material Design

代码语言:javascript
复制
android:elevation="15dp"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34675791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档